Date: Thu, 1 May 2008 01:28:59 GMT From: Peter Wemm <peter@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 140958 for review Message-ID: <200805010128.m411Sxau036343@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=140958 Change 140958 by peter@peter_daintree on 2008/05/01 01:28:01 Snapshot WIP Affected files ... .. //depot/projects/hammer/lib/libkvm/kvm_amd64.c#23 edit Differences ... ==== //depot/projects/hammer/lib/libkvm/kvm_amd64.c#23 (text+ko) ==== @@ -75,6 +75,8 @@ void *mmapbase; size_t mmapsize; pml4_entry_t *PML4; + int mp_maxcpus; + struct pcpu *pcpu; }; /* @@ -355,3 +357,58 @@ } return (_kvm_vatop(kd, va, pa)); } + +static int +_kvm_initpcpu(kvm_t *kd) +{ + struct nlist nlist[2]; + u_long pa; + struct vmstate *vm = kd->vmst; + + nlist[0].n_name = "mp_maxcpus"; + nlist[1].n_name = 0; + if (kvm_nlist(kd, nlist) == 0) { + if (kvm_read(kd, nlist[0].n_value, &vm->mp_maxcpus, + sizeof(vm->mp_maxcpus)) != sizeof(vm->mp_maxcpus)) { + _kvm_err(kd, kd->program, "cannot read mp_maxcpus"); + } else { + /* UP system; symbol doesn't exist */ + vmst->mp_maxcpus = 1; + } + vm->pcpu = _kvm_malloc(kd, sizeof(struct pcpu) * vm->mp_maxcpus); + + nlist[0].n_name = "pcpu"; + nlist[1].n_name = 0; + + if (kvm_nlist(kd, nlist) != 0) { + _kvm_err(kd, kd->program, "bad namelist - no pcpu"); + return (-1); + } + if (kvm_read(kd, nlist[0].n_value, vm->pcpu, + sizeof(struct pcpu) * vm->mp_maxcpus) != + sizeof(struct pcpu) * vm->mp_maxcpus) { + _kvm_err(kd, kd->program, "cannot read pcpu chunk"); + return (-1); + } + return (0); +} + +struct pcpu * +kvm_pcpu_get(kvm_t *kd, int cpu) +{ + struct vmstate *vm = kd->vmst; + + if (ISALIVE(kd)) { + _kvm_err(kd, kd->program, "kvm_initpcpu called in live kernel!"); + return (NULL); + } + if (vm->mp_maxcpus == 0 || vm->pcpu == NULL) { + if (_kvm_initpcpu(kd) != 0) + return (NULL); + } + + if (cpu < 0 || cpu > vm->vm_maxcpus) + _kvm_err(kd, kd->program, " + return (NULL); /* EDOOFUS actually */ + return (&vm->pcpu[cpu]); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805010128.m411Sxau036343>