How To
Summary
Power Systems Servers employing logical partitions can 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 can make the logical partition have a longer uptime duration than the server it is running on. The opposite might 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 by using the read_wall_time function, which returns the number if ticks since the processors were started on this hardware platform. It 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 program uses the AIX function read_wall_time to retrieve the */
/* current timebase */
/* */
/* Copyright 2019, IBM Corporation */
/****************************************************************************/
#include <stdio.h>
#include <sys/time.h>
int main(void)
{
timebasestruct_t start;
unsigned long long int *ticks, timesecs;
unsigned long long int days, hours, minutes, seconds;
/*
Read the timebase into the timebase struct
*/
read_wall_time(&start, TIMEBASE_SZ);
/*
* Set up ticks to point to the high dword of the timebase that was retrieved
* The low dword follows the high dword in timebasestruct_t
*/
ticks = (unsigned long long int*) &start.tb_high;
printf("Timebase 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 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
ibm11078437