Skip to content

Commit

Permalink
Merge pull request #5 from Green-Software-Foundation/teads
Browse files Browse the repository at this point in the history
Scale energy estimate by resource allocation in Teads model
  • Loading branch information
jmcook1186 authored Nov 16, 2023
2 parents 78ea9d8 + 95ff169 commit dd6b47d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
26 changes: 26 additions & 0 deletions src/__tests__/unit/lib/teads-curve/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ describe('teads:configure test', () => {
},
]);
});
test('scale with vcpu usage', async () => {
const outputModel = new TeadsCurveModel();
await outputModel.configure({
'thermal-design-power': 200,
});
await expect(
outputModel.execute([
{
duration: 3600,
'cpu-util': 50.0,
timestamp: '2021-01-01T00:00:00Z',
'vcpus-allocated': 1,
'vcpus-total': 64,
},
])
).resolves.toStrictEqual([
{
'energy-cpu': 0.00234375,
duration: 3600,
'cpu-util': 50.0,
timestamp: '2021-01-01T00:00:00Z',
'vcpus-allocated': 1,
'vcpus-total': 64,
},
]);
});
test('teads:initialize with params:spline', async () => {
const outputModel = new TeadsCurveModel();
await outputModel.configure({
Expand Down
4 changes: 4 additions & 0 deletions src/lib/teads-curve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ IF recognizes the Teads CPU model as `teads-curve`.
- `energy-cpu`: The energy used by the CPU, in kWh


> **Note** If `vcpus-allocated` and `vcpus-total` are available, these data will be used to scale the CPU energy usage. If they are not present, we assume the entire processor is being used. For example, if only 1 out of 64 available vCPUS are allocated, we scale the processor TDP by 1/64.


## Implementation

### Linear Interpolation
Expand Down
35 changes: 23 additions & 12 deletions src/lib/teads-curve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ export class TeadsCurveModel implements ModelPluginInterface {
this.tdp = staticParams['thermal-design-power'] as number;
}

// if ('curve' in staticParams && 'points' in staticParams) {
// this.curve = staticParams?.curve as number[];
// this.points = staticParams?.points as number[];
// if (this.curve.length !== this.points.length) {
// throw new Error(
// 'Number of points and curve values must be the same length'
// );
// }
// this.spline = new Spline(this.points, this.curve);
// }

if ('interpolation' in staticParams) {
this.interpolation = staticParams?.interpolation as Interpolation;
}
Expand All @@ -72,7 +61,29 @@ export class TeadsCurveModel implements ModelPluginInterface {
}
return inputs.map((input: KeyValuePair) => {
this.configure(input);
input['energy-cpu'] = this.calculateEnergy(input);
let energy = this.calculateEnergy(input);
let total: number;
let allocated: number;
if ('vcpus-allocated' in input && 'vcpus-total' in input) {
if (typeof input['vcpus-allocated'] === 'string') {
allocated = parseFloat(input['vcpus-allocated']);
} else if (typeof input['vcpus-allocated'] === 'number') {
allocated = input['vcpus-allocated'];
} else {
throw new Error('invalid type for vcpus-allocated');
}

if (typeof input['vcpus-total'] === 'string') {
total = parseFloat(input['vcpus-total']);
} else if (typeof input['vcpus-total'] === 'number') {
total = input['vcpus-total'];
} else {
throw new Error('invalid type for vcpus-total');
}

energy = energy * (allocated / total);
}
input['energy-cpu'] = energy;
return input;
});
}
Expand Down

0 comments on commit dd6b47d

Please sign in to comment.