Messages in this thread Patch in this message | | | Date | Mon, 17 Nov 2003 16:26:47 -0800 | From | William Lee Irwin III <> | Subject | Re: format_cpumask() |
| |
On Mon, Nov 17, 2003 at 07:22:13PM -0500, Joe Korty wrote: > How about this? (eye-checked only). > static int format_cpumask(char *buf, cpumask_t cpus) > { > int i, d, len = 0; > cpumask_t tmp; > > for(i = (NR_CPUS - 1) & ~3; i >= 0; i -= 4) { > cpus_shift_right(tmp, cpus, i); > d = (int)cpus_coerce(tmp) & 0xf; > buf[len++] = "0123456789abcdef"[d]; > } > return len; > }
I think Keith Owens had a much better suggestion: using '*' in the format string.
===== include/linux/cpumask.h 1.1 vs edited ===== --- 1.1/include/linux/cpumask.h Mon Aug 18 19:46:23 2003 +++ edited/include/linux/cpumask.h Mon Nov 17 16:25:18 2003 @@ -68,4 +68,20 @@ cpu < NR_CPUS; \ cpu = next_online_cpu(cpu,map)) +static inline int format_cpumask(char *buf, cpumask_t cpus) +{ + int k, len = 0; + + for (k = sizeof(cpumask_t)/sizeof(long) - 1; k >= 0; --k) { + int m; + cpumask_t tmp; + + cpus_shift_right(tmp, cpus, BITS_PER_LONG*k); + m = sprintf(buf, "%0*lx", 2*sizeof(long), cpus_coerce(tmp)); + len += m; + buf += m; + } + return len; +} + #endif /* __LINUX_CPUMASK_H */ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |