Skip to content

Commit

Permalink
Merge branch 'dev' into mega-merge-json-apis
Browse files Browse the repository at this point in the history
  • Loading branch information
tpatki authored Jan 18, 2024
2 parents f956b2d + 1e1ce60 commit 2fa1213
Show file tree
Hide file tree
Showing 58 changed files with 1,669 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitlab/cztb2-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ build-cztb2:
- git clone $VARIORUM_ANSIBLE
- cd variorum-ansible-setup
- MOD_TARGET_BRANCH=$(echo "${TARGET_BRANCH}" | tr "/" "_")
- echo "TARGET_BRANCH=${TARGET_BRANCH}"
- echo "MOD_TARGET_BRANCH=${MOD_TARGET_BRANCH}"
- ansible-playbook variorum-powerlab-playbook.yml --extra-vars "branch=${TARGET_BRANCH} modbranch=${MOD_TARGET_BRANCH}"
1 change: 1 addition & 0 deletions scripts/check-cpp-c-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ astyle --errors-to-stdout \
--break-after-logical \
--indent-switches \
--formatted \
--add-brackets \
${FILES}

#
55 changes: 54 additions & 1 deletion src/docs/sphinx/VariorumAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ with the following keys:
The "*" here refers to Socket ID. While more than one socket is supported, our
test systems had only 2 sockets. Note that on the IBM Power9 platform, only the
first socket (Chip-0) has the PWRSYS sensor, which directly reports total node
power. Addtionally, both sockets here report CPU, Memory and GPU power.
power. Additionally, both sockets here report CPU, Memory and GPU power.

On Intel microarchitectures, total node power is not reported by hardware. As a
result, total node power is estimated by adding CPU and DRAM power on both
Expand Down Expand Up @@ -115,6 +115,59 @@ string by reference and includes the following vendor-neutral keys:
- control_units (comma-separated string value)
- control_range (comma-separated string value)

Obtaining Node Utilization
==========================

The API to obtain node utilization has the following format. It takes a string
(``char**``) by reference as input, and populates this string with a JSON object
with total CPU, system CPU, user CPU, total memory, and GPU (when available)
utilizations. It reports the utilization of each available GPU. GPU utilization
is accomplished using the ``int variorum_get_gpu_utilization_json(char
**get_gpu_util_obj_str)`` function. The total memory utilization is computed
using ``/proc/meminfo``, and CPU utilizations is computed using ``/proc/stat``.

The ``variorum_get_node_utilization_json(char **get_util_obj_str)`` function
returns a string type nested JSON object. An example is provided below:

.. code::
{
"hostname": {
"CPU": {
"total_util%": (Real),
"user_util%": (Real),
"system_util%": (Real),
},
"memory_util%": (Real),
"timestamp": (Integer),
"GPU": {
"Socket_*": {
"GPUn*#_util%": (Integer)
}
}
}
}
The ``*`` here refers to socket ID, and the ``#`` refers to GPU ID.

The ``variorum_get_node_utilization_json(char **get_util_obj_str)`` function
returns a string type nested JSON object. An example is provided below:

.. code::
{
"hostname": {
"timestamp": (Integer),
"GPU": {
"Socket_*": {
"GPUn*#_util%": (Integer)
}
}
}
}
The ``*`` here refers to socket ID, and the ``#`` refers to GPU ID.

***************************
Best Effort Power Capping
***************************
Expand Down
6 changes: 6 additions & 0 deletions src/docs/sphinx/api/json_support_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Defined in ``variorum/variorum.h``.
.. doxygenfunction:: variorum_get_node_power_domain_info_json

.. doxygenfunction:: variorum_get_thermals_json

.. doxygenfunction:: variorum_get_node_frequency_json

.. doxygenfunction:: variorum_get_node_utilization_json

.. doxygenfunction:: variorum_get_gpu_utilization_json
16 changes: 10 additions & 6 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,43 @@ add_definitions(-DSECOND_RUN)
set(BASIC_EXAMPLES
variorum-cap-best-effort-node-power-limit-example
variorum-cap-each-core-frequency-limit-example
variorum-cap-gpu-power-limit-example
variorum-cap-gpu-power-ratio-example
variorum-cap-socket-frequency-limit-example
variorum-cap-socket-power-limit-example
variorum-cap-gpu-power-limit-example
variorum-disable-turbo-example
variorum-enable-turbo-example
variorum-get-node-power-json-example
variorum-get-gpu-power-json-example
variorum-get-gpu-utilization-json
variorum-get-node-frequency-json-example
variorum-get-node-power-domain-info-json-example
variorum-get-node-power-json-example
variorum-get-node-thermal-json-example
variorum-integration-using-json-example
variorum-get-node-utilization-json
variorum-get-topology-info-example
variorum-integration-using-json-example
variorum-monitoring-to-file-example
variorum-poll-power-to-file-example
variorum-poll-power-to-stdout-example
variorum-print-available-frequencies-example
variorum-print-frequency-example
variorum-print-counters-example
variorum-print-energy-example
variorum-print-features-example
variorum-print-frequency-example
variorum-print-gpu-utilization-example
variorum-print-hyperthreading-example
variorum-print-power-example
variorum-print-power-limit-example
variorum-print-thermals-example
variorum-print-topology-example
variorum-print-turbo-example
variorum-print-verbose-frequency-example
variorum-print-verbose-counters-example
variorum-print-verbose-frequency-example
variorum-print-verbose-gpu-utilization-example
variorum-print-verbose-power-limit-example
variorum-print-verbose-power-example
variorum-print-verbose-power-limit-example
variorum-print-verbose-thermals-example
variorum-print-energy-example
)

message(STATUS "Adding variorum examples")
Expand Down
88 changes: 88 additions & 0 deletions src/examples/variorum-get-gpu-utilization-json.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2019-2023 Lawrence Livermore National Security, LLC and other
// Variorum Project Developers. See the top-level LICENSE file for details.
//
// SPDX-License-Identifier: MIT

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>

#include <variorum.h>
#include <variorum_topology.h>

#ifdef SECOND_RUN
static inline double do_work(int input)
{
int i;
double result = (double)input;

for (i = 0; i < 100000; i++)
{
result += i * result;
}

return result;
}
#endif

int main(int argc, char **argv)
{
int ret;
char *s = NULL;
#ifdef SECOND_RUN
int i;
int size = 1E4;
volatile double x = 0.0;
#endif

const char *usage = "Usage: %s [-h] [-v]\n";
int opt;
while ((opt = getopt(argc, argv, "hv")) != -1)
{
switch (opt)
{
case 'h':
printf(usage, argv[0]);
return 0;
case 'v':
printf("%s\n", variorum_get_current_version());
return 0;
default:
fprintf(stderr, usage, argv[0]);
return -1;
}
}
ret = variorum_get_gpu_utilization_json(&s);
if (ret != 0)
{
printf("First run: JSON get node utilization failed!\n");
free(s);
exit(-1);
}

/* Print the entire JSON object */
puts(s);

#ifdef SECOND_RUN
for (i = 0; i < size; i++)
{
x += do_work(i);
}
printf("Final result: %f\n", x);
ret = variorum_get_gpu_utilization_json(&s);
if (ret != 0)
{
printf("Second run: JSON get node utilization failed!\n");
free(s);
exit(-1);
}

/* Print the entire JSON object */
puts(s);
#endif

/* Deallocate the string */
free(s);

return ret;
}
45 changes: 45 additions & 0 deletions src/examples/variorum-get-node-frequency-json-example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2019-2023 Lawrence Livermore National Security, LLC and other
// Variorum Project Developers. See the top-level LICENSE file for details.
//
// SPDX-License-Identifier: MIT

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>

#include <variorum.h>

int main(int argc, char **argv)
{
int ret;

const char *usage = "Usage: %s [-h] [-v]\n";
int opt;
while ((opt = getopt(argc, argv, "hv")) != -1)
{
switch (opt)
{
case 'h':
printf(usage, argv[0]);
return 0;
case 'v':
printf("%s\n", variorum_get_current_version());
return 0;
default:
fprintf(stderr, usage, argv[0]);
return -1;
}
}
char *s = NULL;
ret = variorum_get_node_frequency_json(&s);
if (ret != 0)
{
printf("Variorum get frequency json failure!\n");
free(s);
exit(-1);
}
puts(s);
free(s);

return ret;
}
88 changes: 88 additions & 0 deletions src/examples/variorum-get-node-utilization-json.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2019-2023 Lawrence Livermore National Security, LLC and other
// Variorum Project Developers. See the top-level LICENSE file for details.
//
// SPDX-License-Identifier: MIT

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>

#include <variorum.h>
#include <variorum_topology.h>

#ifdef SECOND_RUN
static inline double do_work(int input)
{
int i;
double result = (double)input;

for (i = 0; i < 100000; i++)
{
result += i * result;
}

return result;
}
#endif

int main(int argc, char **argv)
{
int ret;
char *s = NULL;
#ifdef SECOND_RUN
int i;
int size = 1E4;
volatile double x = 0.0;
#endif

const char *usage = "Usage: %s [-h] [-v]\n";
int opt;
while ((opt = getopt(argc, argv, "hv")) != -1)
{
switch (opt)
{
case 'h':
printf(usage, argv[0]);
return 0;
case 'v':
printf("%s\n", variorum_get_current_version());
return 0;
default:
fprintf(stderr, usage, argv[0]);
return -1;
}
}
ret = variorum_get_node_utilization_json(&s);
if (ret != 0)
{
printf("First run: JSON get node utilization failed!\n");
free(s);
exit(-1);
}

/* Print the entire JSON object */
puts(s);

#ifdef SECOND_RUN
for (i = 0; i < size; i++)
{
x += do_work(i);
}
printf("Final result: %f\n", x);
ret = variorum_get_node_utilization_json(&s);
if (ret != 0)
{
printf("Second run: JSON get node utilization failed!\n");
free(s);
exit(-1);
}

/* Print the entire JSON object */
puts(s);
#endif

/* Deallocate the string */
free(s);

return ret;
}
4 changes: 4 additions & 0 deletions src/powmon/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ void parse_json_obj(char *s, int num_sockets)
}

if ((i + 1) == num_sockets)
{
write_header = false;
}
}

}
Expand Down Expand Up @@ -168,7 +170,9 @@ void take_measurement(bool measure_all)

// Verbose output with all sensors/registers
if (measure_all == true)
{
variorum_monitoring(logfile);
}

#if 0
total_joules += rapl_data[0] + rapl_data[1];
Expand Down
Loading

0 comments on commit 2fa1213

Please sign in to comment.