Skip to contentSkip to conversation

syscalls/nice05: Add testcase for nice() syscall

PATCH zhaogongyi via ltp 1 participant 1 message Aug 23, 2022

lore
Share & tools
lore
#0 lore raw

Hi Cyril,

Quoted 51 lines

Hi!

Quoted 14 lines
(quoted diff) +14 -0
+static void verify_nice(void)
+{
+	intptr_t nice_inc_high = -1;
+	intptr_t nice_inc_low = -2;
+	char buf[4096] = {0};
+	float sum_exec_runtime[2];
+	pthread_t nice_low, nice_high;
+	pid_t pid;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		TEST(pthread_barrier_init(&barrier, NULL, 3));
+		if (TST_RET != 0) {
+			tst_brk(TBROK | TTERRNO,

Review

Quoted 10 lines
(quoted diff) +10 -0
+				"pthread_barrier_init() failed");
+		}
+
+		SAFE_PTHREAD_CREATE(&nice_high, NULL, nice_high_thread,
+			(void *)nice_inc_high);
+		SAFE_PTHREAD_CREATE(&nice_low, NULL, nice_low_thread,
+			(void *)nice_inc_low);
+
+		TEST(pthread_barrier_wait(&barrier));
+		if (TST_RET != 0 && TST_RET !=

PTHREAD_BARRIER_SERIAL_THREAD) {

Quoted 10 lines
(quoted diff) +10 -0
+			tst_brk(TBROK | TTERRNO,
+				"pthread_barrier_wait() failed");
+		}
+
+		while (1)
+			pause();
+	}
+
+	sleep(tst_remaining_runtime());
+	SAFE_KILL(pid, SIGSTOP);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+	sprintf(buf, "/proc/%d/sched", child_tid[0]);
+	SAFE_FILE_SCANF(buf, "%*s %*s %*s %*s %*s"
+			"%*s %*s %*f %*s %*s %*f %*s %*s %f",
+			&sum_exec_runtime[0]);
+
+	sprintf(buf, "/proc/%d/sched", child_tid[1]);
+	SAFE_FILE_SCANF(buf, "%*s %*s %*s %*s %*s"
+			"%*s %*s %*f %*s %*s %*f %*s %*s %f",
+			&sum_exec_runtime[1]);

The /proc/$PID/sched file is unfortunatelly only present if CONFIG_SCHED_DEBUG was set in the kernel, which is not always the case, and the test TBROKs on some of my testing targets.

Quoted 2 lines

Thinking of alternatives we can probably do clock_getcpuclockid() for the threads and read the counters with clock_gettime().

The kernel does not support obtaining the CPU-time clock of another process according to man 3,and it would retuen the error number of EFAULT.

And, pthread_getcpuclockid() also can not get the CPU-time of the thread belong to another process.

So, it looks a little tricky.

Quoted 4 lines

--
Cyril Hrubis
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp