Skip to content

Commit

Permalink
netd-init tweaks for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyuanliang committed May 20, 2024
1 parent cdfecbb commit 8598618
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 69 deletions.
2 changes: 1 addition & 1 deletion scripts/build-toybox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -exu
# we're using it for display only so we should be good.
# Toybox sh has more TODOs in multiple areas so don't use it.
# Command mkdir is used for tests only.
toys="base64 mkdir mktemp mv route sort timeout"
toys="base64 mkdir mktemp mv nice route sort timeout"

cd /toybox-*/

Expand Down
50 changes: 41 additions & 9 deletions scripts/inotify/inotify.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright 2022 Google LLC

#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <poll.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -48,14 +50,24 @@ void run_callback_internal(char** callback) {
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));

struct timespec rt;
int ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("inotify: %s exited with status %d (exit: %d)\n",
printf("[%" PRId64 ".%09ld] inotify: %s exited with status %d (exit: %d)\n",
(int64_t)rt.tv_sec, rt.tv_nsec,
callback[0], status, WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("inotify: %s exited with status %d (signal: %d)\n",
callback[0], status, WTERMSIG(status));
printf("[%" PRId64 ".%09ld] inotify: %s exited"
" with status %d (signal: %d = %s)\n",
(int64_t)rt.tv_sec, rt.tv_nsec,
callback[0], status, WTERMSIG(status), strsignal(WTERMSIG(status)));
} else {
printf("inotify: %s exited with status %d\n", callback[0], status);
printf("[%" PRId64 ".%09ld] inotify: %s exited with status %d\n",
(int64_t)rt.tv_sec, rt.tv_nsec, callback[0], status);
}

if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) {
Expand All @@ -80,8 +92,15 @@ void run_callback(char** callback, struct timespec *last, bool always) {
return;
}

printf("inotify: calling %s after %dms since the last run\n",
callback[0], diff_milliseconds);
struct timespec rt;
ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("[%" PRId64 ".%09ld] inotify: calling %s"
" after %dms since the last run\n",
(int64_t)rt.tv_sec, rt.tv_nsec, callback[0], diff_milliseconds);
}

run_callback_internal(callback);
Expand Down Expand Up @@ -128,8 +147,16 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}

struct timespec rt;
int ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("[%" PRId64 ".%09ld] inotify: calling %s as initial run\n",
(int64_t)rt.tv_sec, rt.tv_nsec, callback[0]);

struct timespec tp;
printf("inotify: calling %s as initial run\n", callback[0]);
run_callback(callback, &tp, true);

for (;;) {
Expand Down Expand Up @@ -183,8 +210,13 @@ int main(int argc, char* argv[]) {
continue;
}

printf("inotify: calling %s for %d matching event(s)\n",
callback[0], matches);
ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("[%" PRId64 ".%09ld] inotify: calling %s for %d matching event(s)\n",
(int64_t)rt.tv_sec, rt.tv_nsec, callback[0], matches);
run_callback(callback, &tp, true);
}
}
Loading

0 comments on commit 8598618

Please sign in to comment.