Skip to content
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

Fix bug in bench thread barrier #11

Merged
merged 1 commit into from May 9, 2022

Conversation

kevinshieh0225
Copy link
Contributor

@kevinshieh0225 kevinshieh0225 commented May 2, 2022

The origin version cannot guarantee all the thread starting
kecho task at the same time. Because the main thread
may acquire mutex lock before all the bench_worker have
acquire it.

Change the barrier condition by using counting.

@kevinshieh0225
Copy link
Contributor Author

This is my test code for origin thread barrier.

@jserv
Copy link
Contributor

jserv commented May 2, 2022

I would defer to @foxhoundsk for reviewing.

bench.c Outdated Show resolved Hide resolved
Copy link
Contributor

@foxhoundsk foxhoundsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the rest, thanks for pointing this out!

bench.c Outdated Show resolved Hide resolved
@jserv
Copy link
Contributor

jserv commented May 2, 2022

@eecheng87, Please check if the above change makes sense or not.

bench.c Outdated
@@ -59,7 +59,7 @@ static const char *msg_dum = "dummy message";
static pthread_t pt[MAX_THREAD];

/* block all workers before they are all ready to benchmarking kecho */
static bool ready;
static int ready;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should explain why you change the type of ready within git commit message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ready is used for accumulation, its name would confuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have change the commit message. Please check whether it is clear enough, thank you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name scheme is fairly ambiguous since the word "ready" does not imply the states other than binary form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe changing the variable name to count would be better in this scenerio?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have change the name to ready_cnt, is it a better name scheme?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you intended to count something, you can use retry or n_retry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the name to n_retry, thank you!

bench.c Show resolved Hide resolved
@kevinshieh0225 kevinshieh0225 force-pushed the pthread_barrier branch 2 times, most recently from f97b15f to af1b31b Compare May 2, 2022 06:32
bench.c Outdated Show resolved Hide resolved
@kevinshieh0225 kevinshieh0225 force-pushed the pthread_barrier branch 2 times, most recently from 028ac82 to b31459c Compare May 3, 2022 07:35
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the grammar mistakes in git commit message.

@jserv jserv requested a review from eecheng87 May 4, 2022 02:57
@eecheng87
Copy link
Collaborator

Fix the grammar mistakes in git commit message.

@kevinshieh0225 , I think it could be changed into:

The origin version cannot guarantee all the threads start
kecho task at the same time. Because the main thread
may acquire mutex lock before all the bench_worker have
acquired it.

@kevinshieh0225 kevinshieh0225 force-pushed the pthread_barrier branch 2 times, most recently from 1e10844 to 5188627 Compare May 8, 2022 08:53
@kevinshieh0225
Copy link
Contributor Author

Sorry for the wait, I have change the message grammar.
@eecheng87 thanks for the help!

@eecheng87
Copy link
Collaborator

@jserv , I think this PR is ready to be merged. (I don't have the right to merge it)

bench.c Outdated Show resolved Hide resolved
The origin version cannot guarantee all the threads start
kecho task at the same time. Because the main thread
may acquire mutex lock before all the bench_worker have
acquired it.

Change the barrier condition by using counting:
- Change condition variable to int n_retry for counting.
- The worker acquire lock to add up the counting and wait.
- The last worker reach the condition and broadcast the message.
@jserv jserv merged commit b22466d into sysprog21:master May 9, 2022
@jserv
Copy link
Contributor

jserv commented May 9, 2022

Thank @kevinshieh0225 for this effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants