Bug 146119

Summary: [tools] [patch] (attempt to) cleanup tools/tools/umastat
Product: Base System Reporter: pluknet <pluknet>
Component: miscAssignee: Andriy Gapon <avg>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff
none
umastat.txt none

Description pluknet 2010-04-28 18:20:00 UTC
1) printf() modifiers on LP64
2) warning "dereferencing type-punned pointer will break strict-aliasing rules"
I had to change cast (struct bucketlist *) to (void *) to shut up this warning without much rewrite. *sigh
3) s/kvm_open/kvm_openfiles/;
when using kvm_open, kvm_nlist returns "No such file or directory".
that fixes this warning. I didn't find much difference umastat output.

Fix: Patch attached with submission follows:
Comment 1 pluknet 2010-09-20 23:22:08 UTC
Ok, after some related activity in head, I picked up
this PR from my attic, and couldn't recall the way
to reproduce the kvm_open() issue in ten minutes.
Here are the instructions:

1) before:
# ./umastat -M /dev/mem > /dev/null
umastat: kvm_nlist: No such file or directory
umastat: kvm_nlist: No such file or directory
umastat: kvm_nlist: No such file or directory
umastat: kvm_nlist: No such file or directory

2) after:
# ./umastat -M /dev/mem > /dev/null
#

Somehow I managed to botch the original patch
in PR to non-working state before submitting.
The corrected version attached.

-- 
wbr,
pluknet
Comment 2 dfilter service freebsd_committer freebsd_triage 2010-09-21 06:36:36 UTC
Author: avg
Date: Tue Sep 21 05:36:30 2010
New Revision: 212949
URL: http://svn.freebsd.org/changeset/base/212949

Log:
  tools/umastat: more cleanups
  
  PR:		misc/146119
  Submitted by:	pluknet <pluknet@gmail.com>
  MFC after:	1 week

Modified:
  head/tools/tools/umastat/umastat.c

Modified: head/tools/tools/umastat/umastat.c
==============================================================================
--- head/tools/tools/umastat/umastat.c	Tue Sep 21 04:39:13 2010	(r212948)
+++ head/tools/tools/umastat/umastat.c	Tue Sep 21 05:36:30 2010	(r212949)
@@ -37,6 +37,7 @@
 
 #include <err.h>
 #include <kvm.h>
+#include <limits.h>
 #include <memstat.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -196,7 +197,7 @@ uma_print_keg_align(struct uma_keg *ukp,
 LIST_HEAD(bucketlist, uma_bucket);
 
 static void
-uma_print_bucket(struct uma_bucket *ubp, const char *spaces)
+uma_print_bucket(struct uma_bucket *ubp, const char *spaces __unused)
 {
 
 	printf("{ ub_cnt = %d, ub_entries = %d }", ubp->ub_cnt,
@@ -286,6 +287,7 @@ main(int argc, char *argv[])
 	size_t uzp_userspace_len;
 	char *memf, *nlistf;
 	int ch;
+	char errbuf[_POSIX2_LINE_MAX];
 
 	memf = nlistf = NULL;
 	while ((ch = getopt(argc, argv, "M:N:")) != -1) {
@@ -308,9 +310,9 @@ main(int argc, char *argv[])
 	if (nlistf != NULL && memf == NULL)
 		usage();
 
-	kvm = kvm_open(nlistf, memf, NULL, 0, "umastat");
+	kvm = kvm_openfiles(nlistf, memf, NULL, 0, errbuf);
 	if (kvm == NULL)
-		err(-1, "kvm_open");
+		errx(-1, "kvm_openfiles: %s", errbuf);
 
 	if (kvm_nlist(kvm, namelist) != 0)
 		err(-1, "kvm_nlist");
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 3 Andriy Gapon freebsd_committer freebsd_triage 2010-09-21 06:36:58 UTC
Responsible Changed
From-To: freebsd-bugs->avg

I am handling this
Comment 4 Andriy Gapon freebsd_committer freebsd_triage 2010-09-21 06:37:32 UTC
State Changed
From-To: open->closed

The tool is patched in head, MFC will follow soon. 
Thanks!
Comment 5 dfilter service freebsd_committer freebsd_triage 2010-09-28 06:53:44 UTC
Author: avg
Date: Tue Sep 28 05:53:35 2010
New Revision: 213242
URL: http://svn.freebsd.org/changeset/base/213242

Log:
  MFC r212932,212949: tools/umastat: fix build on amd64 and more
  
  PR:		misc/146119

Modified:
  stable/8/tools/tools/umastat/umastat.c
Directory Properties:
  stable/8/tools/tools/umastat/   (props changed)

Modified: stable/8/tools/tools/umastat/umastat.c
==============================================================================
--- stable/8/tools/tools/umastat/umastat.c	Tue Sep 28 04:57:56 2010	(r213241)
+++ stable/8/tools/tools/umastat/umastat.c	Tue Sep 28 05:53:35 2010	(r213242)
@@ -37,6 +37,7 @@
 
 #include <err.h>
 #include <kvm.h>
+#include <limits.h>
 #include <memstat.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -196,7 +197,7 @@ uma_print_keg_align(struct uma_keg *ukp,
 LIST_HEAD(bucketlist, uma_bucket);
 
 static void
-uma_print_bucket(struct uma_bucket *ubp, const char *spaces)
+uma_print_bucket(struct uma_bucket *ubp, const char *spaces __unused)
 {
 
 	printf("{ ub_cnt = %d, ub_entries = %d }", ubp->ub_cnt,
@@ -230,7 +231,7 @@ uma_print_bucketlist(kvm_t *kvm, struct 
 	}
 
 	printf("\n");
-	printf("%s};  // total cnt %llu, total entries %llu\n", spaces,
+	printf("%s};  // total cnt %ju, total entries %ju\n", spaces,
 	    total_cnt, total_entries);
 }
 
@@ -242,8 +243,8 @@ uma_print_cache(kvm_t *kvm, struct uma_c
 	int ret;
 
 	printf("%s%s[%d] = {\n", spaces, name, cpu);
-	printf("%s  uc_frees = %llu;\n", spaces, cache->uc_frees);
-	printf("%s  uc_allocs = %llu;\n", spaces, cache->uc_allocs);
+	printf("%s  uc_frees = %ju;\n", spaces, cache->uc_frees);
+	printf("%s  uc_allocs = %ju;\n", spaces, cache->uc_allocs);
 
 	if (cache->uc_freebucket != NULL) {
 		ret = kread(kvm, cache->uc_freebucket, &ub, sizeof(ub), 0);
@@ -286,6 +287,7 @@ main(int argc, char *argv[])
 	size_t uzp_userspace_len;
 	char *memf, *nlistf;
 	int ch;
+	char errbuf[_POSIX2_LINE_MAX];
 
 	memf = nlistf = NULL;
 	while ((ch = getopt(argc, argv, "M:N:")) != -1) {
@@ -308,9 +310,9 @@ main(int argc, char *argv[])
 	if (nlistf != NULL && memf == NULL)
 		usage();
 
-	kvm = kvm_open(nlistf, memf, NULL, 0, "umastat");
+	kvm = kvm_openfiles(nlistf, memf, NULL, 0, errbuf);
 	if (kvm == NULL)
-		err(-1, "kvm_open");
+		errx(-1, "kvm_openfiles: %s", errbuf);
 
 	if (kvm_nlist(kvm, namelist) != 0)
 		err(-1, "kvm_nlist");
@@ -412,20 +414,20 @@ main(int argc, char *argv[])
 			}
 			printf("  Zone {\n");
 			printf("    uz_name = \"%s\";\n", name);
-			printf("    uz_allocs = %llu;\n",
+			printf("    uz_allocs = %ju;\n",
 			    uzp_userspace->uz_allocs);
-			printf("    uz_frees = %llu;\n",
+			printf("    uz_frees = %ju;\n",
 			    uzp_userspace->uz_frees);
-			printf("    uz_fails = %llu;\n",
+			printf("    uz_fails = %ju;\n",
 			    uzp_userspace->uz_fails);
 			printf("    uz_fills = %u;\n",
 			    uzp_userspace->uz_fills);
 			printf("    uz_count = %u;\n",
 			    uzp_userspace->uz_count);
-			uma_print_bucketlist(kvm, (struct bucketlist *)
+			uma_print_bucketlist(kvm, (void *)
 			    &uzp_userspace->uz_full_bucket, "uz_full_bucket",
 			    "    ");
-			uma_print_bucketlist(kvm, (struct bucketlist *)
+			uma_print_bucketlist(kvm, (void *)
 			    &uzp_userspace->uz_free_bucket, "uz_free_bucket",
 			    "    ");
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 6 dfilter service freebsd_committer freebsd_triage 2010-09-28 06:57:58 UTC
Author: avg
Date: Tue Sep 28 05:57:50 2010
New Revision: 213243
URL: http://svn.freebsd.org/changeset/base/213243

Log:
  MFC r212932,212949: tools/umastat: fix build on amd64 and more
  
  PR:		misc/146119

Modified:
  stable/7/tools/tools/umastat/umastat.c
Directory Properties:
  stable/7/tools/tools/umastat/   (props changed)

Modified: stable/7/tools/tools/umastat/umastat.c
==============================================================================
--- stable/7/tools/tools/umastat/umastat.c	Tue Sep 28 05:53:35 2010	(r213242)
+++ stable/7/tools/tools/umastat/umastat.c	Tue Sep 28 05:57:50 2010	(r213243)
@@ -37,6 +37,7 @@
 
 #include <err.h>
 #include <kvm.h>
+#include <limits.h>
 #include <memstat.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -196,7 +197,7 @@ uma_print_keg_align(struct uma_keg *ukp,
 LIST_HEAD(bucketlist, uma_bucket);
 
 static void
-uma_print_bucket(struct uma_bucket *ubp, const char *spaces)
+uma_print_bucket(struct uma_bucket *ubp, const char *spaces __unused)
 {
 
 	printf("{ ub_cnt = %d, ub_entries = %d }", ubp->ub_cnt,
@@ -230,7 +231,7 @@ uma_print_bucketlist(kvm_t *kvm, struct 
 	}
 
 	printf("\n");
-	printf("%s};  // total cnt %llu, total entries %llu\n", spaces,
+	printf("%s};  // total cnt %ju, total entries %ju\n", spaces,
 	    total_cnt, total_entries);
 }
 
@@ -242,8 +243,8 @@ uma_print_cache(kvm_t *kvm, struct uma_c
 	int ret;
 
 	printf("%s%s[%d] = {\n", spaces, name, cpu);
-	printf("%s  uc_frees = %llu;\n", spaces, cache->uc_frees);
-	printf("%s  uc_allocs = %llu;\n", spaces, cache->uc_allocs);
+	printf("%s  uc_frees = %ju;\n", spaces, cache->uc_frees);
+	printf("%s  uc_allocs = %ju;\n", spaces, cache->uc_allocs);
 
 	if (cache->uc_freebucket != NULL) {
 		ret = kread(kvm, cache->uc_freebucket, &ub, sizeof(ub), 0);
@@ -286,6 +287,7 @@ main(int argc, char *argv[])
 	size_t uzp_userspace_len;
 	char *memf, *nlistf;
 	int ch;
+	char errbuf[_POSIX2_LINE_MAX];
 
 	memf = nlistf = NULL;
 	while ((ch = getopt(argc, argv, "M:N:")) != -1) {
@@ -308,9 +310,9 @@ main(int argc, char *argv[])
 	if (nlistf != NULL && memf == NULL)
 		usage();
 
-	kvm = kvm_open(nlistf, memf, NULL, 0, "umastat");
+	kvm = kvm_openfiles(nlistf, memf, NULL, 0, errbuf);
 	if (kvm == NULL)
-		err(-1, "kvm_open");
+		errx(-1, "kvm_openfiles: %s", errbuf);
 
 	if (kvm_nlist(kvm, namelist) != 0)
 		err(-1, "kvm_nlist");
@@ -412,20 +414,20 @@ main(int argc, char *argv[])
 			}
 			printf("  Zone {\n");
 			printf("    uz_name = \"%s\";\n", name);
-			printf("    uz_allocs = %llu;\n",
+			printf("    uz_allocs = %ju;\n",
 			    uzp_userspace->uz_allocs);
-			printf("    uz_frees = %llu;\n",
+			printf("    uz_frees = %ju;\n",
 			    uzp_userspace->uz_frees);
-			printf("    uz_fails = %llu;\n",
+			printf("    uz_fails = %ju;\n",
 			    uzp_userspace->uz_fails);
 			printf("    uz_fills = %u;\n",
 			    uzp_userspace->uz_fills);
 			printf("    uz_count = %u;\n",
 			    uzp_userspace->uz_count);
-			uma_print_bucketlist(kvm, (struct bucketlist *)
+			uma_print_bucketlist(kvm, (void *)
 			    &uzp_userspace->uz_full_bucket, "uz_full_bucket",
 			    "    ");
-			uma_print_bucketlist(kvm, (struct bucketlist *)
+			uma_print_bucketlist(kvm, (void *)
 			    &uzp_userspace->uz_free_bucket, "uz_free_bucket",
 			    "    ");
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"