Files
s390-tools/zconf/chp/chpstat/cmg_helper.c
T
Peter Oberparleiter cb77faeae7 chpstat: add tool to display channel-path statistics
Add a new tool named chpstat that can be used to view channel-path
statistics such as utilization and I/O throughput, and to query and
control the status of the channel-path statistics function.

Note: Channel-path statistics are only available on systems running in
      an LPAR or DPM partition.

When run without further options, data for all channel-paths is
displayed repeatedly with a 5 second delay in table format.

Example output:

      CHANNEL-PATH       UTILIZATION(%)   READ(B/s)  WRITE(B/s)
  ID TYP CMG SHR SPEED  PART TOTAL  BUS  PART TOTAL  PART TOTAL
  1d  25   2   1     -  7.16  7.50 7.50  129M  129M  0.00  161K
  21  1b   2   1   32G  0.00  0.00 0.00  0.00  0.00  0.00  0.00
  34  1b   2   1   32G  0.00  0.00 0.00  0.00  0.00  0.00  0.00
  61  25   2   1     -  0.00  0.01 0.00  0.00 2.00K  0.00  307K
  63  25   2   1     -  0.00  0.01 0.00  0.00  0.00  0.00  381K
  bd  11   2   1   10G     -     -    - 529.8 532.1 616.3 616.3

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
2024-05-27 16:52:27 +02:00

110 lines
2.6 KiB
C

/*
* Helper functions for implementing CMG types
*
* Copyright IBM Corp. 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "cmg_helper.h"
#include "cmg.h"
#include "lib/util_base.h"
#include "lib/util_libc.h"
/* Convert time ticks to seconds. */
double tick_to_s(u32 t)
{
return CM_TICK * t;
}
/* Get 32 bit delta of counters @curr and @last. Take into account that both
* counters might have wrapped. Counter width is @width bits. */
u32 get_delta(u32 last, u32 curr, int width)
{
if (curr >= last)
return curr - last;
/* Counter wrapped - add [last..max] + [0..curr] */
return (u32)((u64)(1ULL << width) - last + curr);
}
/* Get 64 bit delta of counters @curr and @last. Take into account that both
* counters might have wrapped. Counter width is @width bits. */
u64 get_delta64(u64 last, u64 curr, int width)
{
u64 max;
if (curr >= last)
return curr - last;
/* Counter wrapped - add [last..max] + [0..curr] */
max = (width == 64) ? ULLONG_MAX : (1ULL << width) - 1;
return (max - last + curr) + 1;
}
/* Check whether word at @offset is valid according to @cuiv. */
bool _cue_valid(u8 cuiv, int offset)
{
int num;
u8 mask;
num = offset / (int)sizeof(u32);
mask = 0x80 >> num;
return (cuiv & mask) != 0;
}
static struct cmg_pair_t *add_pair(struct cmg_pair_t **array, unsigned int *num,
bool valid, const char *key,
enum column_id_t col, enum cmg_unit_t unit,
enum cmg_value_type_t type)
{
struct cmg_pair_t pair;
memset(&pair, 0, sizeof(pair));
pair.valid = valid;
pair.key = util_strdup(key);
pair.col = col;
pair.unit = unit;
pair.type = type;
util_add_array(array, num, pair);
return &((*array)[*num - 1]);
}
void _pr_u32(struct cmg_pair_t **array, unsigned int *num, bool valid,
const char *key, enum column_id_t col, enum cmg_unit_t unit,
u32 value)
{
struct cmg_pair_t *pair;
pair = add_pair(array, num, valid, key, col, unit, CMG_U32);
pair->value_u32 = value;
}
void _pr_u64(struct cmg_pair_t **array, unsigned int *num, bool valid,
const char *key, enum column_id_t col, enum cmg_unit_t unit,
u64 value)
{
struct cmg_pair_t *pair;
pair = add_pair(array, num, valid, key, col, unit, CMG_U64);
pair->value_u64 = value;
}
void _pr_double(struct cmg_pair_t **array, unsigned int *num, bool valid,
const char *key, enum column_id_t col, enum cmg_unit_t unit,
double value)
{
struct cmg_pair_t *pair;
pair = add_pair(array, num, valid, key, col, unit, CMG_FLOAT);
pair->value_double = value;
}