IBM Support

AIX Example HW Platform uptime

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

This document provides a sample of how to use the timebase to determine the hardware platform runtime.  The calculations are valid for P8 and P9 processor subsystems that all use the same number of timebase ticks per microsecond (512).  This program can be compiled on AIX and moved to IBM i to be run in PASE under Qshell.

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

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"HW1A1","label":"IBM Power Systems"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}},{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"TI0005E","label":"Power System S914 Server"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}},{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"HW1A1","label":"IBM Power Systems"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}},{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"TI0005G","label":"Power System S922 Server (9009-22A)"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}},{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"TI0007E","label":"Power System E950 Server (9040-MR9)"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}},{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"TI0007I","label":"Power System E980 Server (9080-M9S)"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
07 December 2021

UID

ibm11078437