From owner-p4-projects@FreeBSD.ORG Thu Aug 2 21:14:38 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3328516A46D; Thu, 2 Aug 2007 21:14:38 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4BCC16A41B; Thu, 2 Aug 2007 21:14:37 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from anuket.mj.niksun.com (gwnew.niksun.com [65.115.46.162]) by mx1.freebsd.org (Postfix) with ESMTP id 29E4613C4B5; Thu, 2 Aug 2007 21:14:36 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from niksun.com (anuket [10.70.0.5]) by anuket.mj.niksun.com (8.13.6/8.13.6) with ESMTP id l72LEamT042765; Thu, 2 Aug 2007 17:14:36 -0400 (EDT) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim To: perforce@FreeBSD.org Date: Thu, 2 Aug 2007 17:14:31 -0400 User-Agent: KMail/1.6.2 References: <200708021130.l72BUHrY077198@repoman.freebsd.org> <200708021356.58217.jkim@FreeBSD.org> <20070802192936.GA49511@freebsd.org> In-Reply-To: <20070802192936.GA49511@freebsd.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200708021714.33543.jkim@FreeBSD.org> X-Virus-Scanned: ClamAV 0.90.2/3848/Thu Aug 2 16:22:06 2007 on anuket.mj.niksun.com X-Virus-Status: Clean Cc: Roman Divacky Subject: Re: PERFORCE change 124529 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2007 21:14:38 -0000 On Thursday 02 August 2007 03:29 pm, Roman Divacky wrote: > On Thu, Aug 02, 2007 at 01:56:34PM -0400, Jung-uk Kim wrote: > > On Thursday 02 August 2007 07:30 am, Roman Divacky wrote: > > > + > > > +/* XXX: fake one.. waiting for ssouhlal to commit his patch */ > > > +int > > > +linux_sched_getaffinity(struct thread *td, struct > > > linux_sched_getaffinity_args *args) +{ > > > + int error; > > > + cpumask_t i = ~0; > > > + > > > + if (args->len < sizeof(cpumask_t)) > > > + return (EINVAL); > > > + > > > + error = copyout(&i, args->user_mask_ptr, sizeof(cpumask_t)); > > > + return (error); > > > +} > > > > Er, shouldn't it be more like this? > > > > int > > linux_sched_getaffinity(struct thread *td, > > struct linux_sched_getaffinity_args *args) > > { > > uint8_t *mask; > > int error; > > > > if (args->cpusetsize < sizeof(cpumask_t)) > > return (EINVAL); > > > > mask = malloc(args->cpusetsize, M_LINUX, M_WAITOK); > > memset(mask, 0xff, args->cpusetsize); > > error = copyout(mask, args->mask, args->cpusetsize); > > free(mask, M_LINUX); > > > > return (error); > > } > > hm.. I looked at it and in my version the cpumask_t (linux one) is > defined to be bit array of configurable length. I dont know what is > the default but I think its quite safe to assume that its 128. Yes, it was but not any more. Basically it depends on Linux kernel configuration option, i.e., maximum number of CPUs. Since the bit 0 is CPU 0, bit 1 is CPU 1, etc, you have to make sure the last bits are properly set. If you really had to do i = ~0, you probably wanted to do casting first, e.g., i = ~(cpumask_t)0 to make sure. Of course my version doesn't have to worry about it. ;-) > but still.. the prototype is: > > asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, > unsigned long __user > *user_mask_ptr) > > and the len is not used anywhere in the code to dynamically size > it. I wonder how to deal with that. The prototype I gave you was from manual page, not the kernel source: http://www.linuxhowtos.org/manpages/2/sched_getaffinity.htm While googling, I found many interesting sched_getaffinity() API issues but this seems to summarize it nicely: http://jeff.squyres.com/journal/archives/2005/10/linux_processor.html Interesting history... AFAIK, cpumask_t is not dynamically sized as I said but cpu_set_t is. Glibc or application just defines cpu_set_t type via CPU_SETSIZE() macro and calls sched_getaffinity(). Then, the kernel returns sizeof(cpumask_t), so that user can determine the actual size of cpumask_t - thanks for catching it, BTW. Jung-uk Kim