Skip to contentSkip to conversation

ftracetest: Do not use usleep

PATCH Superseded Namhyung Kim 4 participants 7 messages Mar 26, 2015 – Mar 31, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftracetest: Do not use usleep

The usleep is only provided on distros from Redhat so running ftracetest on other distro resulted in failures due to the missing usleep.

The reason of using [u]sleep in the test was to generate (scheduler) events. But as we use 'cat trace | grep | wc -l' to read the events, the command themselves already generate some events before reading the trace file so no need to call [u]sleep explicitly.

---
 tools/testing/selftests/ftrace/test.d/event/event-enable.tc     | 3 ---
 tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc | 3 ---
 2 files changed, 6 deletions(-)
tools/testing/selftests/ftrace/test.d/event/event-enable.tc +0 -3
index 668616d9bb03..7c7b4ce383a3 100644
@@ -21,7 +21,6 @@ reset_tracer
 do_reset
 
 echo 'sched:sched_switch' > set_event
-usleep 1
 
 count=`cat trace | grep sched_switch | wc -l`
 if [ $count -eq 0 ]; then
@@ -31,7 +30,6 @@ fi
 do_reset
 
 echo 1 > events/sched/sched_switch/enable
-usleep 1
 
 count=`cat trace | grep sched_switch | wc -l`
 if [ $count -eq 0 ]; then
@@ -41,7 +39,6 @@ fi
 do_reset
 
 echo 0 > events/sched/sched_switch/enable
-usleep 1
 
 count=`cat trace | grep sched_switch | wc -l`
 if [ $count -ne 0 ]; then
tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc +0 -3
index 655c415b6e7f..08a9459224b0 100644
@@ -21,7 +21,6 @@ reset_tracer
 do_reset
 
 echo 'sched:*' > set_event
-usleep 1
 
 count=`cat trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
 if [ $count -lt 3 ]; then
@@ -31,7 +30,6 @@ fi
 do_reset
 
 echo 1 > events/sched/enable
-usleep 1
 
 count=`cat trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
 if [ $count -lt 3 ]; then
@@ -41,7 +39,6 @@ fi
 do_reset
 
 echo 0 > events/sched/enable
-usleep 1
 
 count=`cat trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
 if [ $count -ne 0 ]; then
Signature · 1 line
2.3.3
#1 lore raw
Quoted 8 lines · Namhyung Kim

The usleep is only provided on distros from Redhat so running ftracetest on other distro resulted in failures due to the missing usleep.

The reason of using [u]sleep in the test was to generate (scheduler) events. But as we use 'cat trace | grep | wc -l' to read the events, the command themselves already generate some events before reading the trace file so no need to call [u]sleep explicitly.

Quoted 6 lines

---

Hi Steve,

I will pull this in for 4.1. Assume that is ok. Just confirming.

thanks,
-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
maintainer
#2 lore raw
In reply to Namhyung Kim
Quoted 7 lines · On Thu, 26 Mar 2015 09:32:23 +0900 Namhyung Kim <[email protected]> wrote:

The usleep is only provided on distros from Redhat so running ftracetest on other distro resulted in failures due to the missing usleep.

The reason of using [u]sleep in the test was to generate (scheduler) events. But as we use 'cat trace | grep | wc -l' to read the events, the command themselves already generate some events before reading the trace file so no need to call [u]sleep explicitly.

Note, opening "trace" via cat stops tracing. There is a possible race where the cat will not produce events. My worry is that if the shell implements its own "cat" command, it may not fork, and open the trace file. Which would not have any events in it, and opening it will disable the rest of the command from having events.

What about using:

ping localhost -c 1

?

-- Steve

#3 lore raw

Hi Steve,

Quoted 11 lines · Steven Rostedt
Quoted 7 lines · On Thu, 26 Mar 2015 09:32:23 +0900 Namhyung Kim <[email protected]> wrote:

The usleep is only provided on distros from Redhat so running ftracetest on other distro resulted in failures due to the missing usleep.

The reason of using [u]sleep in the test was to generate (scheduler) events. But as we use 'cat trace | grep | wc -l' to read the events, the command themselves already generate some events before reading the trace file so no need to call [u]sleep explicitly.

Quoted 5 lines

Note, opening "trace" via cat stops tracing. There is a possible race where the cat will not produce events. My worry is that if the shell implements its own "cat" command, it may not fork, and open the trace file. Which would not have any events in it, and opening it will disable the rest of the command from having events.

I understand your point. But this is not just cat, it needs grep and wc also. So I think there should be scheduler event(s).

Quoted 6 lines

What about using:

ping localhost -c 1

?

I'm okay with ping though but worried if some tiny system might lack the ping command..

Thanks,
Namhyung

maintainer
#4 lore raw
Quoted 3 lines · On Tue, 31 Mar 2015 09:48:55 +0900 Namhyung Kim <[email protected]> wrote:

I understand your point. But this is not just cat, it needs grep and wc also. So I think there should be scheduler event(s).

Yes, and cat opens 'trace', which will disable tracing, and if that happens before grep and wc, then those events will not show up.

There was a time when these tests use to fail without adding something to force a schedule, that's why I feel it's safe to add something.

-- Steve

#5 lore raw
In reply to Namhyung Kim
Quoted 24 lines · Namhyung Kim

Hi Steve,

Quoted 11 lines · Steven Rostedt
Quoted 7 lines · On Thu, 26 Mar 2015 09:32:23 +0900 Namhyung Kim <[email protected]> wrote:

The usleep is only provided on distros from Redhat so running ftracetest on other distro resulted in failures due to the missing usleep.

The reason of using [u]sleep in the test was to generate (scheduler) events. But as we use 'cat trace | grep | wc -l' to read the events, the command themselves already generate some events before reading the trace file so no need to call [u]sleep explicitly.

Quoted 5 lines

Note, opening "trace" via cat stops tracing. There is a possible race where the cat will not produce events. My worry is that if the shell implements its own "cat" command, it may not fork, and open the trace file. Which would not have any events in it, and opening it will disable the rest of the command from having events.

I understand your point. But this is not just cat, it needs grep and wc also. So I think there should be scheduler event(s).

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

What about using:

ping localhost -c 1

?

I'm okay with ping though but worried if some tiny system might lack the ping command..

I'd use a fallback method like:

  yield() { sleep .001 || usleep 1 || sleep 1; }

Then just s/usleep 1/yield/

cheers,
Pádraig.

maintainer
#6 lore raw
Quoted 8 lines · On Tue, 31 Mar 2015 02:08:06 +0100 Pádraig Brady <[email protected]> wrote:
Quoted 2 lines

I'm okay with ping though but worried if some tiny system might lack the ping command..

I'd use a fallback method like:

  yield() { sleep .001 || usleep 1 || sleep 1; }

Then just s/usleep 1/yield/

yield() { ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1; } ;-)

-- Steve