Skip to contentSkip to conversation

question on pktgen shutdown logic.

DISCUSSION Ben Greear 2 participants 5 messages May 22, 2013

Subsystems (2)
lore
Share & tools
lore

Ben Greear

author
#0 lore raw

While looking at pktgen.c in 3.9.3, I cannot explain how it does not race on shutdown.

The thread worker checks for pktgen_exiting, and will bail out of it's main loop and initiate cleanup if this is true.

The pg_net_exit sets the pktgen_exiting to true, and then proceedes to call

		kthread_stop(t->tsk);
		kfree(t);

What I don't understand is what keeps the kfree(t) from happening before the thread has noticed pktgen_exiting is set and properly bailed out of it's loop and finished cleanup?

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#1 lore raw
Quoted 9 lines · Ben Greear

While looking at pktgen.c in 3.9.3, I cannot explain how it does not race on shutdown.

The thread worker checks for pktgen_exiting, and will bail out of it's main loop and initiate cleanup if this is true.

The pg_net_exit sets the pktgen_exiting to true, and then proceedes to call

Quoted 6 lines
		kthread_stop(t->tsk);
		kfree(t);

What I don't understand is what keeps the kfree(t) from happening before the thread has noticed pktgen_exiting is set and properly bailed out of it's loop and finished cleanup?

kthread_stop() is synchronous.

author
#2 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 9 lines · Ben Greear

While looking at pktgen.c in 3.9.3, I cannot explain how it does not race on shutdown.

The thread worker checks for pktgen_exiting, and will bail out of it's main loop and initiate cleanup if this is true.

The pg_net_exit sets the pktgen_exiting to true, and then proceedes to call

Quoted 8 lines
Quoted 6 lines
		kthread_stop(t->tsk);
		kfree(t);

What I don't understand is what keeps the kfree(t) from happening before the thread has noticed pktgen_exiting is set and properly bailed out of it's loop and finished cleanup?

kthread_stop() is synchronous.

Ahh, so it waits for the pktgen_thread_worker method to return?

Why do we bother with the pktgen_exiting flag at all...it would seem that just checking kthread_should_stop() would do the trick?

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#3 lore raw
Quoted 5 lines · Ben Greear

Ahh, so it waits for the pktgen_thread_worker method to return?

Why do we bother with the pktgen_exiting flag at all...it would seem that just checking kthread_should_stop() would do the trick?

If you have 4096 cpus, setting pktgen_exiting permits all pktgen exiting faster.

Otherwise you wait about 400 seconds (4096 * HZ/10)

author
#4 lore raw
Quoted 4 lines · Eric Dumazet
Quoted 2 lines · Ben Greear

Ahh, so it waits for the pktgen_thread_worker method to return?

Quoted 8 lines
Quoted 3 lines

Why do we bother with the pktgen_exiting flag at all...it would seem that just checking kthread_should_stop() would do the trick?

If you have 4096 cpus, setting pktgen_exiting permits all pktgen exiting faster.

Otherwise you wait about 400 seconds (4096 * HZ/10)

Ok, I think I understand now.

Thanks,
Ben

Quoted 2 lines
Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com