Skip to content

Commit

Permalink
Make omrsysinfo_get_CPU_load() return another error code on first call
Browse files Browse the repository at this point in the history
This is to help getSystemCpuLoad() determine if it's the first call.

Related: eclipse-openj9/openj9#18451

Signed-off-by: Gengchen Tuo <[email protected]>
  • Loading branch information
thallium committed Nov 23, 2023
1 parent 419dc95 commit b664465
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions include_core/omrporterror.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define OMRPORT_ERROR_INVALID_HANDLE (OMRPORT_ERROR_BASE-17)
#define OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM (OMRPORT_ERROR_BASE-18)
#define OMRPORT_ERROR_INVALID_ARGUMENTS (OMRPORT_ERROR_BASE-19)
#define OMRPORT_ERROR_INSUFFICIENT_DATA (OMRPORT_ERROR_BASE-20)
/** @} */

/**
Expand Down
2 changes: 1 addition & 1 deletion port/common/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ omrsysinfo_get_CPU_utilization(struct OMRPortLibrary *portLibrary, struct J9Sysi
*
* @return
* - 0 on success
* - \arg OMRPORT_ERROR_OPFAILED on the first two invocations of this API
* - \arg OMRPORT_ERROR_INSUFFICIENT_DATA on the first two invocations of this API
* - \arg OMRPORT_ERROR_OPFAILED if less than 10ns have passed since the second call to this API
* - negative portable error code on other failures
*/
Expand Down
4 changes: 2 additions & 2 deletions port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4642,7 +4642,7 @@ omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
if (oldestCPUTime->timestamp == 0) {
*oldestCPUTime = currentCPUTime;
*latestCPUTime = currentCPUTime;
return OMRPORT_ERROR_OPFAILED;
return OMRPORT_ERROR_INSUFFICIENT_DATA;
}

/* Calculate using the most recent value in the history */
Expand Down Expand Up @@ -4674,7 +4674,7 @@ omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
if (oldestCPUTime->timestamp == 0) {
*oldestCPUTime = currentCPUTime;
*latestCPUTime = currentCPUTime;
return OMRPORT_ERROR_OPFAILED;
return OMRPORT_ERROR_INSUFFICIENT_DATA;
}

/* Calculate using the most recent value in the history */
Expand Down
2 changes: 1 addition & 1 deletion port/win32/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
if (oldestCPUTime->timestamp == 0) {
*oldestCPUTime = currentCPUTime;
*latestCPUTime = currentCPUTime;
return OMRPORT_ERROR_OPFAILED;
return OMRPORT_ERROR_INSUFFICIENT_DATA;
}

/* Calculate using the most recent value in the history */
Expand Down

0 comments on commit b664465

Please sign in to comment.