static int pset(int subcode, long arg1, long arg2, long arg3, long arg4) { switch (subcode) { case PSET_CREATE: return (pset_create((psetid_t *)arg1)); case PSET_DESTROY: return (pset_destroy((psetid_t)arg1)); case PSET_ASSIGN: return (pset_assign((psetid_t)arg1, (processorid_t)arg2, (psetid_t *)arg3, 0)); case PSET_INFO: return (pset_info((psetid_t)arg1, (int *)arg2, (uint_t *)arg3, (processorid_t *)arg4)); case PSET_BIND: return (pset_bind((psetid_t)arg1, (idtype_t)arg2, (id_t)arg3, (psetid_t *)arg4)); case PSET_GETLOADAVG: return (pset_getloadavg((psetid_t)arg1, (int *)arg2, (int)arg3)); case PSET_LIST: return (pset_list((psetid_t *)arg1, (uint_t *)arg2)); case PSET_SETATTR: return (pset_setattr((psetid_t)arg1, (uint_t)arg2)); case PSET_GETATTR: return (pset_getattr((psetid_t)arg1, (uint_t *)arg2)); case PSET_ASSIGN_FORCED: return (pset_assign((psetid_t)arg1, (processorid_t)arg2, (psetid_t *)arg3, 1)); default: return (set_errno(EINVAL)); } }
static int acquire_psets(struct snapshot *ss) { psetid_t *pids = NULL; struct pset_snapshot *ps; size_t pids_nr; size_t i, j; /* * Careful in this code. We have to use pset_list * twice, but inbetween pids_nr can change at will. * We delay the setting of s_nr_psets until we have * the "final" value of pids_nr. */ if (pset_list(NULL, &pids_nr) < 0) return (errno); if ((pids = calloc(pids_nr, sizeof (psetid_t))) == NULL) goto out; if (pset_list(pids, &pids_nr) < 0) goto out; ss->s_psets = calloc(pids_nr + 1, sizeof (struct pset_snapshot)); if (ss->s_psets == NULL) goto out; ss->s_nr_psets = pids_nr + 1; /* CPUs not in any actual pset */ ps = &ss->s_psets[0]; ps->ps_id = 0; ps->ps_cpus = calloc(ss->s_nr_cpus, sizeof (struct cpu_snapshot *)); if (ps->ps_cpus == NULL) goto out; /* CPUs in a a pset */ for (i = 1; i < ss->s_nr_psets; i++) { ps = &ss->s_psets[i]; ps->ps_id = pids[i - 1]; ps->ps_cpus = calloc(ss->s_nr_cpus, sizeof (struct cpu_snapshot *)); if (ps->ps_cpus == NULL) goto out; } for (i = 0; i < ss->s_nr_psets; i++) { ps = &ss->s_psets[i]; for (j = 0; j < ss->s_nr_cpus; j++) { if (!CPU_ACTIVE(&ss->s_cpus[j])) continue; if (ss->s_cpus[j].cs_pset_id != ps->ps_id) continue; ps->ps_cpus[ps->ps_nr_cpus++] = &ss->s_cpus[j]; } } errno = 0; out: free(pids); return (errno); }