IBM Support

PPC64 Linux Example HW Platform uptime

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

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).

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

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"HW1A1","label":"IBM Power Systems"},"Component":"","Platform":[{"code":"PF016","label":"Linux"}],"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":"PF016","label":"Linux"}],"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":"PF016","label":"Linux"}],"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":"PF016","label":"Linux"}],"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":"PF016","label":"Linux"}],"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":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
07 December 2021

UID

ibm11078425