Skip to content

Commit d141b16

Browse files
author
Octavian Purdila
authored
Merge pull request torvalds#219 from opurdila/small-fixes
Small fixes and enhancements
2 parents 1e947fb + c14dc91 commit d141b16

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

tools/lkl/lib/nt-host.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void thread_exit(void)
8484
static int thread_join(lkl_thread_t tid)
8585
{
8686
/* TODO: error handling */
87-
WaitForSingleObject(tid, INFINITE);
87+
WaitForSingleObject((void *)tid, INFINITE);
8888
return 0;
8989
}
9090

tools/lkl/lib/posix-host.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ static void *tls_get(unsigned int key)
223223

224224
static unsigned long long time_ns(void)
225225
{
226-
struct timeval tv;
226+
struct timespec ts;
227227

228-
gettimeofday(&tv, NULL);
228+
clock_gettime(CLOCK_MONOTONIC, &ts);
229229

230-
return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000ULL;
230+
return 1e9*ts.tv_sec + ts.tv_nsec;
231231
}
232232

233233
static void *timer_alloc(void (*fn)(void *), void *arg)

tools/lkl/tests/boot.c

+56-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,59 @@ int test_getpid(char *str, int len)
112112
return TEST_FAILURE;
113113
}
114114

115+
void check_latency(long (*f)(void), long *min, long *max, long *avg)
116+
{
117+
int i;
118+
unsigned long long start, stop, sum = 0;
119+
static const int count = 1000;
120+
long delta;
121+
122+
*min = 1000000000;
123+
*max = -1;
124+
125+
for (i = 0; i < count; i++) {
126+
start = lkl_host_ops.time();
127+
f();
128+
stop = lkl_host_ops.time();
129+
delta = stop - start;
130+
if (*min > delta)
131+
*min = delta;
132+
if (*max < delta)
133+
*max = delta;
134+
sum += delta;
135+
}
136+
*avg = sum / count;
137+
}
138+
139+
static long native_getpid(void)
140+
{
141+
#ifdef __MINGW32__
142+
GetCurrentProcessId();
143+
#else
144+
getpid();
145+
#endif
146+
return 0;
147+
}
148+
149+
int test_syscall_latency(char *str, int len)
150+
{
151+
long min, max, avg;
152+
int tmp;
153+
154+
check_latency(lkl_sys_getpid, &min, &max, &avg);
155+
156+
tmp = snprintf(str, len, "avg/min/max lkl: %ld/%ld/%ld ",
157+
avg, min, max);
158+
str += tmp;
159+
len -= tmp;
160+
161+
check_latency(native_getpid, &min, &max, &avg);
162+
163+
snprintf(str, len, "native: %ld/%ld/%ld", avg, min, max);
164+
165+
return TEST_SUCCESS;
166+
}
167+
115168
#define access_rights 0721
116169

117170
int test_creat(char *str, int len)
@@ -676,6 +729,7 @@ static void test_thread(void *data)
676729
fprintf(stderr, "%s: %s\n", __func__, lkl_strerror(ret));
677730
}
678731

732+
lkl_stop_syscall_thread();
679733
}
680734

681735
static int test_syscall_thread(char *str, int len)
@@ -817,9 +871,10 @@ int main(int argc, char **argv)
817871
if (cla.tap_ifname)
818872
TEST(netdev_add);
819873
#endif /* __MINGW32__ */
820-
lkl_start_kernel(&lkl_host_ops, 16 * 1024 * 1024, "");
874+
lkl_start_kernel(&lkl_host_ops, 16 * 1024 * 1024, "loglevel=8");
821875

822876
TEST(getpid);
877+
TEST(syscall_latency);
823878
TEST(umask);
824879
TEST(creat);
825880
TEST(close);

tools/lkl/tests/test.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ static int g_test_pass = 0;
1616
\
1717
printf("%-20s %s [%s]\n", #name, \
1818
ret == TEST_SUCCESS ? "passed" : "failed", str); \
19+
fflush(stdout); \
1920
}
2021

0 commit comments

Comments
 (0)