How To
Summary
Power Systems Servers employing logical partitions may encounter scenarios where it is necessary to know the hardware platform uptime as opposed to the uptime of the logical partition. The array of availability tools for these platforms may make the logical partition have a longer uptime duration than the server it is running on. The opposite may also be true. As a result, operating system runtime as determined by the uptime command cannot be relied upon for the hardware platform runtime. But, the hardware platform runtime can be determined using the __ppc_get_timebase() function which returns the number if ticks since the processors were started on this hardware platform. This is effectively the hardware platform uptime.
Objective
Additional Information
/****************************************************************************/
/* Sample program to retrieve the current hardware runtime in ticks and */
/* Convert that value to days, minutes, hours, and seconds */
/* */
/* This example uses PPC64 linux function __ppc_get_timebase to retrieve */
/* the current timebase */
/* */
/* Copyright 2019, IBM Corporation */
/****************************************************************************/
#include <sys/platform/ppc.h>
#include <stdio.h>
int main(void)
{
uint64_t ticks, timesecs;
uint64_t days, hours, minutes, seconds;
/*
* Read the timebase
*/
ticks = __ppc_get_timebase();
printf("ticks = 0x%016llx (%llu)\n ", ticks, ticks);
/*
* There are 512 ticks / microsecond. We need seconds.
*/
timesecs = ticks / 512000000;
/*
* Convert seconds to days, minutes, hours and seconds
*/
seconds = timesecs % 60;
minutes = (timesecs / 60) % 60;
hours = (timesecs / 3600) % 24;
days = (timesecs / 86400);
/*
* Print the results
*/
printf("Platform has been up for %llu seconds.\n", timesecs);
printf("Platform runtime is: %llu days, %llu hours, %llu minutes, "
"%llu seconds.\n", days, hours, minutes, seconds);
}
Document Location
Worldwide
Was this topic helpful?
Document Information
Modified date:
07 December 2021
UID
ibm11078425