Commit 874a6a4d authored by Sridutt Bhalachandra's avatar Sridutt Bhalachandra

Modified c downstream api to support transmission of info needed by power policy (acr)

parent 24ddf2db
#include "nrm.h"
/* Filename: downstream.c
*
* Description: This file contains the implementation of downstream API to
* transmit application context information to NRM.
*
* The application context information transmitted is used to monitor
* application progress and/or invoke power policies to improve energy
* efficiency at the node level.
*/
#include "downstream_api.h"
#include<zmq.h>
#include<stdio.h>
#include<unistd.h>
......@@ -10,7 +20,7 @@ int nrm_init(struct nrm_context *ctxt, const char *uuid)
{
assert(ctxt != NULL);
assert(uuid != NULL);
char *uri = getenv(NRM_ENV_URI);
const char *uri = getenv(NRM_ENV_URI);
if(uri == NULL)
uri = NRM_DEFAULT_URI;
ctxt->container_uuid = getenv("ARGO_CONTAINER_UUID");
......@@ -50,7 +60,8 @@ int nrm_send_progress(struct nrm_context *ctxt, unsigned long progress)
long long int timediff = (now.tv_nsec - ctxt->time.tv_nsec) +
1e9* (now.tv_sec - ctxt->time.tv_sec);
ctxt->acc += progress;
if(timediff > NRM_RATELIMIT_THRESHOLD) {
if(timediff > NRM_RATELIMIT_THRESHOLD)
{
snprintf(buf, 512, NRM_PROGRESS_FORMAT, ctxt->acc, ctxt->app_uuid);
int err = zmq_send(ctxt->socket, buf, strnlen(buf, 512), 0);
assert(err > 0);
......@@ -59,3 +70,24 @@ int nrm_send_progress(struct nrm_context *ctxt, unsigned long progress)
ctxt->time = now;
return 0;
}
int nrm_invoke_power_policy(struct nrm_context *ctxt, int cpu, double
startCompute, double endCompute, double startBarrier, double
endBarrier)
{
char buf[512];
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
long long int timediff = (now.tv_nsec - ctxt->time.tv_nsec) +
1e9* (now.tv_sec - ctxt->time.tv_sec);
if(timediff > NRM_RATELIMIT_THRESHOLD)
{
snprintf(buf, 512, NRM_POWER_POLICY_FORMAT, cpu, startCompute,
endCompute, startBarrier, endBarrier, ctxt->app_uuid);
int err = zmq_send(ctxt->socket, buf, strnlen(buf, 512), 0);
assert(err > 0);
}
ctxt->time = now;
return 0;
}
/* Filename: downstream_api.h
*
* Includes required headers, functions and parameters used by NRM downstream
* interface
*
*/
#ifndef NRM_H
#define NRM_H 1
......@@ -21,11 +28,15 @@ struct nrm_context {
#define NRM_START_FORMAT "{\"type\":\"application\", \"event\":\"start\", \"container\": \"%s\", \"uuid\": \"%s\", \"progress\": true, \"threads\": null}"
#define NRM_PROGRESS_FORMAT "{\"type\":\"application\", \"event\":\"progress\", \"payload\": \"%lu\", \"uuid\": \"%s\"}"
#define NRM_POWER_POLICY_FORMAT "{\"type\":\"application\", \"event\":\"power_policy\", \"cpu\": \"%d\", \"startcompute\": \"%lf\", \"endcompute\": \"%lf\", \"startbarrier\": \"%lf\", \"endbarrier\": \"%lf\", \"uuid\": \"%s\"}"
#define NRM_EXIT_FORMAT "{\"type\":\"application\", \"event\":\"exit\", \"uuid\": \"%s\"}"
int nrm_init(struct nrm_context *, const char *);
int nrm_fini(struct nrm_context *);
int nrm_send_progress(struct nrm_context *, unsigned long);
int nrm_invoke_power_policy(struct nrm_context *ctxt, int cpu, double
startCompute, double endCompute, double startBarrier, double
endBarrier);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment