Date: Thu, 1 May 2008 14:49:33 -0400 From: John Baldwin <jhb@freebsd.org> To: Peter Wemm <peter@freebsd.org> Cc: Perforce Change Reviews <perforce@freebsd.org> Subject: Re: PERFORCE change 140994 for review Message-ID: <200805011449.33465.jhb@freebsd.org> In-Reply-To: <200805011738.m41HcLq2038321@repoman.freebsd.org> References: <200805011738.m41HcLq2038321@repoman.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805011449.33465.jhb>