-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dlt-system: Avoid expensive getpid() syscalls #717
base: master
Are you sure you want to change the base?
Conversation
Thanks for the finding, do you have any references for us to refer @aleixpol |
I'm sorry, what references are you referring to? |
I found doc of getpid enter and exit syscall on internet, thanks. |
include/dlt/dlt_user.h.in
Outdated
@@ -271,6 +271,10 @@ typedef struct | |||
#ifdef DLT_TRACE_LOAD_CTRL_ENABLE | |||
pthread_rwlock_t trace_load_limit_lock; | |||
#endif | |||
// Since glibc 2.25, getpid() no longer caches the PID, instead performing a | |||
// full syscall every time. This means we're performing a full syscall | |||
// roundtrip for *every* *single* *log* *message* on the system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Kindly please shorten these lines for variable definitions and align your comment with the standard used in the DltUser struct ?
Ex: /* Local DltUser process identifier */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still wait for author to refactor here? if yes then @aleixpol can you push latest patch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
src/lib/dlt_user.c
Outdated
@@ -4011,7 +4014,11 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * | |||
/* send session id */ | |||
if (dlt_user.with_session_id) { | |||
msg.standardheader->htyp |= DLT_HTYP_WSID; | |||
msg.headerextra.seid = (uint32_t) getpid(); | |||
// 99.99999% of the time, we'll already have a PID set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this comment? You're right, but it is better to remove this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we actually dont need it, unless any dev really want to know the func call then gcc doc already mentioned in detail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution , can you check my comments?
Hello @aleixpol |
GCC reference: __builtin_expect() |
Hello @aleixpol , hello @minminlittleshrimp , hello @Bichdao021195 , hello @lti9hc , i have verified the change with the test code at: dlt-daemon/src/tests/dlt-test-fork-handler.c |
That's cool, will approve and merge after latest patchset uploaded |
Since glibc 2.25, getpid() no longer caches the PID, instead performing a full syscall every time. This means we're performing a full syscall roundtrip for *every* *single* *log* *message* on the system. This patch caches the result of getpid() when appropriate, avoiding unnessicary syscalls. Signed-off-by: Aleix Pol Gonzalez <[email protected]>
7167c39
to
34d8272
Compare
Since glibc 2.25, getpid() no longer caches the PID, instead performing a full syscall every time. This means we're performing a full syscall roundtrip for every single log message on the system.
This patch caches the result of getpid() when appropriate, avoiding unnessicary syscalls.