Add getpid to measure the performance of system calls

This commit is contained in:
LI Qing 2024-04-19 16:32:19 +08:00 committed by Tate, Hongliang Tian
parent d28292cec4
commit 0ecb919e73
4 changed files with 56 additions and 2 deletions

View File

@ -8,7 +8,20 @@ CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
INITRAMFS ?= $(CUR_DIR)/../build/initramfs
REGRESSION_BUILD_DIR ?= $(INITRAMFS)/regression
TEST_APPS := signal_c pthread network hello_world hello_pie hello_c fork_c fork execve pty mongoose
# These test apps are sorted by name
TEST_APPS := \
execve \
fork \
fork_c \
getpid \
hello_c \
hello_pie \
hello_world \
mongoose \
network \
pthread \
pty \
signal_c \
C_SOURCES := $(shell find . -type f \( -name "*.c" -or -name "*.h" \) )

View File

@ -0,0 +1,5 @@
# SPDX-License-Identifier: MPL-2.0
include ../test_common.mk
EXTRA_C_FLAGS :=

View File

@ -0,0 +1,36 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
#define NUM_OF_CALLS 1000000
int main()
{
struct timespec start, end;
long seconds, nanoseconds, total_nanoseconds, avg_latency;
pid_t pid;
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < NUM_OF_CALLS; i++) {
pid = syscall(SYS_getpid);
}
clock_gettime(CLOCK_MONOTONIC, &end);
seconds = end.tv_sec - start.tv_sec;
nanoseconds = end.tv_nsec - start.tv_nsec;
total_nanoseconds = seconds * 1e9 + nanoseconds;
avg_latency = total_nanoseconds / NUM_OF_CALLS;
printf("Process %d executed the getpid() syscall %d times.\n", pid,
NUM_OF_CALLS);
printf("Syscall average latency: %ld nanoseconds.\n", avg_latency);
return 0;
}

View File

@ -8,7 +8,7 @@ SCRIPT_DIR=/regression
cd ${SCRIPT_DIR}/..
echo "Start process test......"
tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty"
tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty getpid/getpid"
for testcase in ${tests}
do
echo "Running test ${testcase}......"