Skip to contentSkip to conversation

Documentation: fix getdelays.c example -l option and segv

PATCH In review Michael Neuling 3 participants 9 messages Aug 10, 2007 – Aug 15, 2007 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation: fix getdelays.c example -l option and segv

Fix a couple of minor issues with the getdelays.c example code.

---
 Documentation/accounting/getdelays.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Documentation/accounting/getdelays.c +11 -10
Index: linux-2.6-ozlabs/Documentation/accounting/getdelays.c
===================================================================
@@ -196,7 +196,7 @@ void print_delayacct(struct taskstats *t
 	       "IO    %15s%15s\n"
 	       "      %15llu%15llu\n"
 	       "MEM   %15s%15s\n"
-	       "      %15llu%15llu\n"
+	       "      %15llu%15llu\n",
 	       "count", "real total", "virtual total", "delay total",
 	       t->cpu_count, t->cpu_run_real_total, t->cpu_run_virtual_total,
 	       t->cpu_delay_total,
@@ -335,17 +335,17 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	if (tid) {
-		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
-			      cmd_type, &tid, sizeof(__u32));
-		PRINTF("Sent pid/tgid, retval %d\n", rc);
-		if (rc < 0) {
-			fprintf(stderr, "error sending tid/tgid cmd\n");
-			goto done;
+	do {
+		if (tid) {
+			rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
+				      cmd_type, &tid, sizeof(__u32));
+			PRINTF("Sent pid/tgid, retval %d\n", rc);
+			if (rc < 0) {
+				fprintf(stderr, "error sending tid/tgid cmd\n");
+				goto done;
+			}
 		}
-	}
 
-	do {
 		int i;
 
 		rep_len = recv(nl_sd, &msg, sizeof(msg), 0);
@@ -430,6 +430,7 @@ int main(int argc, char *argv[])
 			}
 			na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
 		}
+		sleep(2);
 	} while (loop);
 done:
 	if (maskset) {
#1 lore raw
Quoted 1 line · On Fri, 10 Aug 2007 18:24:45 +1000 Michael Neuling <[email protected]> wrote:

Fix a couple of minor issues with the getdelays.c example code.

What issues?

#2 lore raw
Quoted 3 lines
Quoted 1 line

Fix a couple of minor issues with the getdelays.c example code.

What issues?

-l option (loop) doesn't work and it seg faults in print_delayacct.

Mikey

#3 lore raw
In reply to Michael Neuling
Quoted 12 lines · Michael Neuling

Fix a couple of minor issues with the getdelays.c example code.

---
 Documentation/accounting/getdelays.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Index: linux-2.6-ozlabs/Documentation/accounting/getdelays.c
===================================================================

Documentation/accounting/getdelays.c void print_delayacct(struct taskstats *t · line 199

Quoted 5 lines
Documentation/accounting/getdelays.c +1 -1
@@ -196,7 +196,7 @@ void print_delayacct(struct taskstats *t
 	       "IO    %15s%15s\n"
 	       "      %15llu%15llu\n"
 	       "MEM   %15s%15s\n"
-	       "      %15llu%15llu\n"
+	       "      %15llu%15llu\n",

This change looks good!

Quoted 31 lines
Documentation/accounting/getdelays.c +9 -9
 	       "count", "real total", "virtual total", "delay total",
 	       t->cpu_count, t->cpu_run_real_total, t->cpu_run_virtual_total,
 	       t->cpu_delay_total,
@@ -335,17 +335,17 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	if (tid) {
-		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
-			      cmd_type, &tid, sizeof(__u32));
-		PRINTF("Sent pid/tgid, retval %d\n", rc);
-		if (rc < 0) {
-			fprintf(stderr, "error sending tid/tgid cmd\n");
-			goto done;
+	do {
+		if (tid) {
+			rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
+				      cmd_type, &tid, sizeof(__u32));
+			PRINTF("Sent pid/tgid, retval %d\n", rc);
+			if (rc < 0) {
+				fprintf(stderr, "error sending tid/tgid cmd\n");
+				goto done;
+			}
 		}
-	}
 
-	do {
 		int i;
 
 		rep_len = recv(nl_sd, &msg, sizeof(msg), 0);

Documentation/accounting/getdelays.c int main(int argc, char *argv[]) · line 433

Quoted 4 lines
Documentation/accounting/getdelays.c +1 -0
@@ -430,6 +430,7 @@ int main(int argc, char *argv[])
 			}
 			na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
 		}
+		sleep(2);

Is this really required? a sleep() in the code. Why do we do multiple send_cmd()'s in the do loop? I'll test and get back.

Quoted 7 lines
Documentation/accounting/getdelays.c +0 -0
 	} while (loop);
 done:
 	if (maskset) {
Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
#4 lore raw
Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 7 lines · Michael Neuling

Fix a couple of minor issues with the getdelays.c example code.

---
 Documentation/accounting/getdelays.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Quoted 12 lines

Documentation/accounting/getdelays.c void print_delayacct(struct taskstats *t · line 199

Quoted 10 lines

Index: linux-2.6-ozlabs/Documentation/accounting/getdelays.c
===================================================================

Documentation/accounting/getdelays.c +1 -1
@@ -196,7 +196,7 @@ void print_delayacct(struct taskstats *t
 	       "IO    %15s%15s\n"
 	       "      %15llu%15llu\n"
 	       "MEM   %15s%15s\n"
-	       "      %15llu%15llu\n"
+	       "      %15llu%15llu\n",

This change looks good!

Looks like it was randomly removed in b663a79c191508f27cd885224b592a878c0ba0f6.

Quoted 8 lines
Quoted 8 lines
Documentation/accounting/getdelays.c +0 -0
 	       "count", "real total", "virtual total", "delay total",
 	       t->cpu_count, t->cpu_run_real_total, t->cpu_run_virtual_total,
 	       t->cpu_delay_total,
@@ -335,17 +335,17 @@ int main(int argc, char *argv[])
 		}
 	}
 
Quoted 14 lines
Quoted 4 lines
Documentation/accounting/getdelays.c +0 -4
-	if (tid) {
-		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
-			      cmd_type, &tid, sizeof(__u32));
-		PRINTF("Sent pid/tgid, retval %d\n", rc);

Documentation/accounting/getdelays.c int main(int argc, char *argv[])

Quoted 10 lines
Documentation/accounting/getdelays.c +7 -3
-		if (rc < 0) {
-			fprintf(stderr, "error sending tid/tgid cmd\n");
-			goto done;
+	do {
+		if (tid) {
+			rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
+				      cmd_type, &tid, sizeof(__u32));
+			PRINTF("Sent pid/tgid, retval %d\n", rc);
+			if (rc < 0) {
+				fprintf(stderr, "error sending tid/tgid cmd\n")

;

Quoted 8 lines
Quoted 8 lines
Documentation/accounting/getdelays.c +2 -2
+				goto done;
+			}
 		}
-	}
 
-	do {
 		int i;
 
Quoted 9 lines

Documentation/accounting/getdelays.c int main(int argc, char *argv[]) · line 433

Quoted 6 lines
Documentation/accounting/getdelays.c +1 -0
 		rep_len = recv(nl_sd, &msg, sizeof(msg), 0);
@@ -430,6 +430,7 @@ int main(int argc, char *argv[])
 			}
 			na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
 		}
+		sleep(2);

Is this really required? a sleep() in the code. Why do we do multiple send_cmd()'s in the do loop? I'll test and get back.

I needed to send another command to receive more data. Without the per loop send_cmd, I never got any more stats.

Should we receive more data without the additional send_cmd? I've been running with:
./getdelays -d -p 1 -l

Mikey

#5 lore raw

<snip>

Quoted 10 lines
Quoted 2 lines

Is this really required? a sleep() in the code. Why do we do multiple send_cmd()'s in the do loop? I'll test and get back.

I needed to send another command to receive more data. Without the per loop send_cmd, I never got any more stats.

Should we receive more data without the additional send_cmd? I've been running with:
./getdelays -d -p 1 -l

Interesting, we never used -l that way. We used -l to get data for all exiting tasks

./getdelays -d -l

For the usage you've mentioned, I'd use

while :
do

	sleep 2
	./getdelays -p 1 -d

done

I guess your changes change getdelays and since there are other ways to obtaining the same data, I'd remove the last bit of changes made to send the TGID often to get data.

Quoted 3 lines

Mikey

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
#6 lore raw
Quoted 9 lines

Interesting, we never used -l that way. We used -l to get data for all exiting tasks

./getdelays -d -l

For the usage you've mentioned, I'd use

while :
do

Quoted 7 lines
	sleep 2
	./getdelays -p 1 -d

done

I guess your changes change getdelays and since there are other ways to obtaining the same data, I'd remove the last bit of changes made to send the TGID often to get data.

Ok. I'll resubmit with just the first fix.

Mikey

#7 lore raw

PATCH 1/1 Documentation: fix getdelays.c printf bug

In reply to Balbir Singh

b663a79c191508f27cd885224b592a878c0ba0f6 incorrectly removed a comma from a printf statement. This causes corruption in the output printing or a seg fault.

---
 Documentation/accounting/getdelays.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

akpm: please replace documentation-fix-getdelaysc-example-l-option-and-segv.patch with this.

Documentation/accounting/getdelays.c +1 -1
Index: linux-2.6-ozlabs/Documentation/accounting/getdelays.c
===================================================================
@@ -196,7 +196,7 @@ void print_delayacct(struct taskstats *t
 	       "IO    %15s%15s\n"
 	       "      %15llu%15llu\n"
 	       "MEM   %15s%15s\n"
-	       "      %15llu%15llu\n"
+	       "      %15llu%15llu\n",
 	       "count", "real total", "virtual total", "delay total",
 	       t->cpu_count, t->cpu_run_real_total, t->cpu_run_virtual_total,
 	       t->cpu_delay_total,
Acked-by on v1 1/1
#8 lore raw

Re: [PATCH] Documentation: fix getdelays.c printf bug

Quoted 17 lines · Michael Neuling

b663a79c191508f27cd885224b592a878c0ba0f6 incorrectly removed a comma from a printf statement. This causes corruption in the output printing or a seg fault.

---
 Documentation/accounting/getdelays.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

akpm: please replace documentation-fix-getdelaysc-example-l-option-and-segv.patch with this.

Index: linux-2.6-ozlabs/Documentation/accounting/getdelays.c
===================================================================

Documentation/accounting/getdelays.c void print_delayacct(struct taskstats *t · line 202

Quoted 8 lines
Documentation/accounting/getdelays.c +1 -1
@@ -196,7 +196,7 @@ void print_delayacct(struct taskstats *t
 	       "IO    %15s%15s\n"
 	       "      %15llu%15llu\n"
 	       "MEM   %15s%15s\n"
-	       "      %15llu%15llu\n"
+	       "      %15llu%15llu\n",
 	       "count", "real total", "virtual total", "delay total",
 	       t->cpu_count, t->cpu_run_real_total, t->cpu_run_virtual_total,
 	       t->cpu_delay_total,

This is exactly what Maxim had sent as well.

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL