提交 a6c02e29 编写于 作者: V vcbchang

fix:修复在使用GetCputime时由clockid计算pid或tid时出现的错误

【背景】原来代码在计算由clockid计算pid或tid时用的是移位的方式,由于对于有符号和无符号数结果可能不一致,故这里对计算方法做了修改,修改为计算clockid的逆运算。

【修改方案】
计算pid或tid为计算clockid的逆运算

re #I4249G
Signed-off-by: Nvcbchang <vcbchang@qq.com>
Change-Id: I2952232ec7d8fc2d0c47163b00d0c772648a2bf8
上级 ce66a234
......@@ -452,11 +452,25 @@ int clock_settime(clockid_t clockID, const struct timespec *tp)
}
#ifdef LOSCFG_KERNEL_CPUP
inline UINT32 GetTidFromClockID(clockid_t clockID)
{
// In musl/src/thread/pthread_getcpuclockid.c, we know 'clockid = (-tid - 1) * 8 + 6'
UINT32 tid = -(clockID - 6) / 8 - 1; // 6 8 1 inverse operation from clockID to tid
return tid;
}
inline const pid_t GetPidFromClockID(clockid_t clockID)
{
// In musl/src/time/clock_getcpuclockid.c, we know 'clockid = (-pid - 1) * 8 + 2'
const pid_t pid = -(clockID - 2) / 8 - 1; // 2 8 1 inverse operation from clockID to pid
return pid;
}
static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
{
uint64_t runtime;
UINT32 intSave;
UINT32 tid = ((UINT32) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
UINT32 tid = GetTidFromClockID(clockID);
if (OS_TID_CHECK_INVALID(tid)) {
return -EINVAL;
......@@ -482,7 +496,7 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
{
UINT64 runtime;
UINT32 intSave;
const pid_t pid = ((pid_t) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
const pid_t pid = GetPidFromClockID(clockID);
LosProcessCB *spcb = NULL;
if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
......@@ -524,7 +538,7 @@ static int GetCputime(clockid_t clockID, struct timespec *tp)
static int CheckClock(const clockid_t clockID)
{
int error = 0;
const pid_t pid = ((pid_t) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
const pid_t pid = GetPidFromClockID(clockID);
if (!((UINT32)clockID & CPUCLOCK_PERTHREAD_MASK)) {
LosProcessCB *spcb = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册