From owner-p4-projects@FreeBSD.ORG Thu May 1 18:52:36 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 41C861065675; Thu, 1 May 2008 18:52:36 +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 026E4106567B; Thu, 1 May 2008 18:52:36 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id D564A8FC1F; Thu, 1 May 2008 18:52:35 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unknown [208.65.91.234]) by elvis.mu.org (Postfix) with ESMTP id 66CBC1A4D82; Thu, 1 May 2008 11:52:35 -0700 (PDT) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.14.2/8.14.2) with ESMTP id m41IqJWs025345; Thu, 1 May 2008 14:52:20 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: Peter Wemm Date: Thu, 1 May 2008 14:49:33 -0400 User-Agent: KMail/1.9.7 References: <200805011738.m41HcLq2038321@repoman.freebsd.org> In-Reply-To: <200805011738.m41HcLq2038321@repoman.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805011449.33465.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Thu, 01 May 2008 14:52:20 -0400 (EDT) X-Virus-Scanned: ClamAV 0.91.2/7007/Thu May 1 11:34:23 2008 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Perforce Change Reviews Subject: Re: PERFORCE change 140994 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, 01 May 2008 18:52:36 -0000 On Thursday 01 May 2008 01:38:21 pm Peter Wemm wrote: > http://perforce.freebsd.org/chv.cgi?CH=140994 > > Change 140994 by peter@peter_daintree on 2008/05/01 17:37:28 > > Update. Use the correct fields. Look for pcpu_size in the kernel > to adapt to any layout changes. (Let the consumer deal with variance > rather than guaranteeing that libkvm breaks first) You do know about this MI array in kern/subr_pcpu.c? struct pcpu *cpuid_to_pcpu[MAXCPU]; struct cpuhead cpuhead = SLIST_HEAD_INITIALIZER(cpuhead); You can use that to make this all MI instead of reading __pcpu. Either walk the cpuhead list or the array and just read the pcpu structs one at a time. > Affected files ... > > .. //depot/projects/hammer/lib/libkvm/kvm_amd64.c#24 edit > > Differences ... > > ==== //depot/projects/hammer/lib/libkvm/kvm_amd64.c#24 (text+ko) ==== > > @@ -76,7 +76,8 @@ > size_t mmapsize; > pml4_entry_t *PML4; > int mp_maxcpus; > - struct pcpu *pcpu; > + int pcpu_recsize; > + char *pcpu; > }; > > /* > @@ -375,9 +376,23 @@ > /* UP system; symbol doesn't exist */ > vmst->mp_maxcpus = 1; > } > - vm->pcpu = _kvm_malloc(kd, sizeof(struct pcpu) * vm->mp_maxcpus); > + /* > + * The __pcpu array may have different inter-record padding or may > + * grow additional fields. We have to adapt the best we can. > + */ > + nlist[0].n_name = "pcpu_size"; > + nlist[1].n_name = 0; > + if (kvm_nlist(kd, nlist) == 0) { > + if (kvm_read(kd, nlist[0].n_value, &vm->pcpu_recsize, > + sizeof(vm->pcpu_recsize)) != sizeof(vm->pcpu_recsize)) { > + _kvm_err(kd, kd->program, "cannot read pcpu_size"); > + } else { > + /* Older kernel's dont have it. Hope for the best. */ > + vmst->pcpu_recsize = sizeof(struct pcpu); > + } > + vm->pcpu = _kvm_malloc(kd, vm->pcpu_recsize * vm->mp_maxcpus); > > - nlist[0].n_name = "pcpu"; > + nlist[0].n_name = "__pcpu"; > nlist[1].n_name = 0; > > if (kvm_nlist(kd, nlist) != 0) { > @@ -385,8 +400,8 @@ > return (-1); > } > if (kvm_read(kd, nlist[0].n_value, vm->pcpu, > - sizeof(struct pcpu) * vm->mp_maxcpus) != > - sizeof(struct pcpu) * vm->mp_maxcpus) { > + vm->pcpu_recsize * vm->mp_maxcpus) != > + vm->pcpu_recsize * vm->mp_maxcpus) { > _kvm_err(kd, kd->program, "cannot read pcpu chunk"); > return (-1); > } > @@ -407,8 +422,8 @@ > return (NULL); > } > > - if (cpu < 0 || cpu > vm->vm_maxcpus) > + if (cpu < 0 || cpu > vm->vm_maxcpus) > _kvm_err(kd, kd->program, " > return (NULL); /* EDOOFUS actually */ > - return (&vm->pcpu[cpu]); > + return ((struct pcpu *)&vm->pcpu[cpu * vm->pcpu_recsize]); > } > -- John Baldwin