16ff6d951SJohn Birrell /* 26ff6d951SJohn Birrell * CDDL HEADER START 36ff6d951SJohn Birrell * 46ff6d951SJohn Birrell * The contents of this file are subject to the terms of the 56ff6d951SJohn Birrell * Common Development and Distribution License (the "License"). 66ff6d951SJohn Birrell * You may not use this file except in compliance with the License. 76ff6d951SJohn Birrell * 86ff6d951SJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 96ff6d951SJohn Birrell * or http://www.opensolaris.org/os/licensing. 106ff6d951SJohn Birrell * See the License for the specific language governing permissions 116ff6d951SJohn Birrell * and limitations under the License. 126ff6d951SJohn Birrell * 136ff6d951SJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each 146ff6d951SJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 156ff6d951SJohn Birrell * If applicable, add the following below this CDDL HEADER, with the 166ff6d951SJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying 176ff6d951SJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner] 186ff6d951SJohn Birrell * 196ff6d951SJohn Birrell * CDDL HEADER END 206ff6d951SJohn Birrell */ 216ff6d951SJohn Birrell 226ff6d951SJohn Birrell /* 236ff6d951SJohn Birrell * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 246ff6d951SJohn Birrell * Use is subject to license terms. 256ff6d951SJohn Birrell */ 266ff6d951SJohn Birrell 276ff6d951SJohn Birrell #pragma ident "%Z%%M% %I% %E% SMI" 286ff6d951SJohn Birrell 296ff6d951SJohn Birrell #include <stdlib.h> 306ff6d951SJohn Birrell #include <strings.h> 316ff6d951SJohn Birrell #include <errno.h> 326ff6d951SJohn Birrell #include <unistd.h> 336ff6d951SJohn Birrell #include <dt_impl.h> 346ff6d951SJohn Birrell #include <assert.h> 35d9ce0144SJohn Birrell #if defined(sun) 366ff6d951SJohn Birrell #include <alloca.h> 37d9ce0144SJohn Birrell #else 38d9ce0144SJohn Birrell #include <sys/sysctl.h> 390f2bd1e8SRui Paulo #include <libproc_compat.h> 40d9ce0144SJohn Birrell #endif 416ff6d951SJohn Birrell #include <limits.h> 426ff6d951SJohn Birrell 436ff6d951SJohn Birrell #define DTRACE_AHASHSIZE 32779 /* big 'ol prime */ 446ff6d951SJohn Birrell 456ff6d951SJohn Birrell /* 466ff6d951SJohn Birrell * Because qsort(3C) does not allow an argument to be passed to a comparison 476ff6d951SJohn Birrell * function, the variables that affect comparison must regrettably be global; 486ff6d951SJohn Birrell * they are protected by a global static lock, dt_qsort_lock. 496ff6d951SJohn Birrell */ 506ff6d951SJohn Birrell static pthread_mutex_t dt_qsort_lock = PTHREAD_MUTEX_INITIALIZER; 516ff6d951SJohn Birrell 526ff6d951SJohn Birrell static int dt_revsort; 536ff6d951SJohn Birrell static int dt_keysort; 546ff6d951SJohn Birrell static int dt_keypos; 556ff6d951SJohn Birrell 566ff6d951SJohn Birrell #define DT_LESSTHAN (dt_revsort == 0 ? -1 : 1) 576ff6d951SJohn Birrell #define DT_GREATERTHAN (dt_revsort == 0 ? 1 : -1) 586ff6d951SJohn Birrell 596ff6d951SJohn Birrell static void 606ff6d951SJohn Birrell dt_aggregate_count(int64_t *existing, int64_t *new, size_t size) 616ff6d951SJohn Birrell { 62d9ce0144SJohn Birrell uint_t i; 636ff6d951SJohn Birrell 646ff6d951SJohn Birrell for (i = 0; i < size / sizeof (int64_t); i++) 656ff6d951SJohn Birrell existing[i] = existing[i] + new[i]; 666ff6d951SJohn Birrell } 676ff6d951SJohn Birrell 686ff6d951SJohn Birrell static int 696ff6d951SJohn Birrell dt_aggregate_countcmp(int64_t *lhs, int64_t *rhs) 706ff6d951SJohn Birrell { 716ff6d951SJohn Birrell int64_t lvar = *lhs; 726ff6d951SJohn Birrell int64_t rvar = *rhs; 736ff6d951SJohn Birrell 746ff6d951SJohn Birrell if (lvar < rvar) 756ff6d951SJohn Birrell return (DT_LESSTHAN); 766ff6d951SJohn Birrell 776ff6d951SJohn Birrell if (lvar > rvar) 786ff6d951SJohn Birrell return (DT_GREATERTHAN); 796ff6d951SJohn Birrell 806ff6d951SJohn Birrell return (0); 816ff6d951SJohn Birrell } 826ff6d951SJohn Birrell 836ff6d951SJohn Birrell /*ARGSUSED*/ 846ff6d951SJohn Birrell static void 856ff6d951SJohn Birrell dt_aggregate_min(int64_t *existing, int64_t *new, size_t size) 866ff6d951SJohn Birrell { 876ff6d951SJohn Birrell if (*new < *existing) 886ff6d951SJohn Birrell *existing = *new; 896ff6d951SJohn Birrell } 906ff6d951SJohn Birrell 916ff6d951SJohn Birrell /*ARGSUSED*/ 926ff6d951SJohn Birrell static void 936ff6d951SJohn Birrell dt_aggregate_max(int64_t *existing, int64_t *new, size_t size) 946ff6d951SJohn Birrell { 956ff6d951SJohn Birrell if (*new > *existing) 966ff6d951SJohn Birrell *existing = *new; 976ff6d951SJohn Birrell } 986ff6d951SJohn Birrell 996ff6d951SJohn Birrell static int 1006ff6d951SJohn Birrell dt_aggregate_averagecmp(int64_t *lhs, int64_t *rhs) 1016ff6d951SJohn Birrell { 1026ff6d951SJohn Birrell int64_t lavg = lhs[0] ? (lhs[1] / lhs[0]) : 0; 1036ff6d951SJohn Birrell int64_t ravg = rhs[0] ? (rhs[1] / rhs[0]) : 0; 1046ff6d951SJohn Birrell 1056ff6d951SJohn Birrell if (lavg < ravg) 1066ff6d951SJohn Birrell return (DT_LESSTHAN); 1076ff6d951SJohn Birrell 1086ff6d951SJohn Birrell if (lavg > ravg) 1096ff6d951SJohn Birrell return (DT_GREATERTHAN); 1106ff6d951SJohn Birrell 1116ff6d951SJohn Birrell return (0); 1126ff6d951SJohn Birrell } 1136ff6d951SJohn Birrell 1146ff6d951SJohn Birrell static int 1156ff6d951SJohn Birrell dt_aggregate_stddevcmp(int64_t *lhs, int64_t *rhs) 1166ff6d951SJohn Birrell { 1176ff6d951SJohn Birrell uint64_t lsd = dt_stddev((uint64_t *)lhs, 1); 1186ff6d951SJohn Birrell uint64_t rsd = dt_stddev((uint64_t *)rhs, 1); 1196ff6d951SJohn Birrell 1206ff6d951SJohn Birrell if (lsd < rsd) 1216ff6d951SJohn Birrell return (DT_LESSTHAN); 1226ff6d951SJohn Birrell 1236ff6d951SJohn Birrell if (lsd > rsd) 1246ff6d951SJohn Birrell return (DT_GREATERTHAN); 1256ff6d951SJohn Birrell 1266ff6d951SJohn Birrell return (0); 1276ff6d951SJohn Birrell } 1286ff6d951SJohn Birrell 1296ff6d951SJohn Birrell /*ARGSUSED*/ 1306ff6d951SJohn Birrell static void 1316ff6d951SJohn Birrell dt_aggregate_lquantize(int64_t *existing, int64_t *new, size_t size) 1326ff6d951SJohn Birrell { 1336ff6d951SJohn Birrell int64_t arg = *existing++; 1346ff6d951SJohn Birrell uint16_t levels = DTRACE_LQUANTIZE_LEVELS(arg); 1356ff6d951SJohn Birrell int i; 1366ff6d951SJohn Birrell 1376ff6d951SJohn Birrell for (i = 0; i <= levels + 1; i++) 1386ff6d951SJohn Birrell existing[i] = existing[i] + new[i + 1]; 1396ff6d951SJohn Birrell } 1406ff6d951SJohn Birrell 1416ff6d951SJohn Birrell static long double 1426ff6d951SJohn Birrell dt_aggregate_lquantizedsum(int64_t *lquanta) 1436ff6d951SJohn Birrell { 1446ff6d951SJohn Birrell int64_t arg = *lquanta++; 1456ff6d951SJohn Birrell int32_t base = DTRACE_LQUANTIZE_BASE(arg); 1466ff6d951SJohn Birrell uint16_t step = DTRACE_LQUANTIZE_STEP(arg); 1476ff6d951SJohn Birrell uint16_t levels = DTRACE_LQUANTIZE_LEVELS(arg), i; 1486ff6d951SJohn Birrell long double total = (long double)lquanta[0] * (long double)(base - 1); 1496ff6d951SJohn Birrell 1506ff6d951SJohn Birrell for (i = 0; i < levels; base += step, i++) 1516ff6d951SJohn Birrell total += (long double)lquanta[i + 1] * (long double)base; 1526ff6d951SJohn Birrell 1536ff6d951SJohn Birrell return (total + (long double)lquanta[levels + 1] * 1546ff6d951SJohn Birrell (long double)(base + 1)); 1556ff6d951SJohn Birrell } 1566ff6d951SJohn Birrell 1576ff6d951SJohn Birrell static int64_t 1586ff6d951SJohn Birrell dt_aggregate_lquantizedzero(int64_t *lquanta) 1596ff6d951SJohn Birrell { 1606ff6d951SJohn Birrell int64_t arg = *lquanta++; 1616ff6d951SJohn Birrell int32_t base = DTRACE_LQUANTIZE_BASE(arg); 1626ff6d951SJohn Birrell uint16_t step = DTRACE_LQUANTIZE_STEP(arg); 1636ff6d951SJohn Birrell uint16_t levels = DTRACE_LQUANTIZE_LEVELS(arg), i; 1646ff6d951SJohn Birrell 1656ff6d951SJohn Birrell if (base - 1 == 0) 1666ff6d951SJohn Birrell return (lquanta[0]); 1676ff6d951SJohn Birrell 1686ff6d951SJohn Birrell for (i = 0; i < levels; base += step, i++) { 1696ff6d951SJohn Birrell if (base != 0) 1706ff6d951SJohn Birrell continue; 1716ff6d951SJohn Birrell 1726ff6d951SJohn Birrell return (lquanta[i + 1]); 1736ff6d951SJohn Birrell } 1746ff6d951SJohn Birrell 1756ff6d951SJohn Birrell if (base + 1 == 0) 1766ff6d951SJohn Birrell return (lquanta[levels + 1]); 1776ff6d951SJohn Birrell 1786ff6d951SJohn Birrell return (0); 1796ff6d951SJohn Birrell } 1806ff6d951SJohn Birrell 1816ff6d951SJohn Birrell static int 1826ff6d951SJohn Birrell dt_aggregate_lquantizedcmp(int64_t *lhs, int64_t *rhs) 1836ff6d951SJohn Birrell { 1846ff6d951SJohn Birrell long double lsum = dt_aggregate_lquantizedsum(lhs); 1856ff6d951SJohn Birrell long double rsum = dt_aggregate_lquantizedsum(rhs); 1866ff6d951SJohn Birrell int64_t lzero, rzero; 1876ff6d951SJohn Birrell 1886ff6d951SJohn Birrell if (lsum < rsum) 1896ff6d951SJohn Birrell return (DT_LESSTHAN); 1906ff6d951SJohn Birrell 1916ff6d951SJohn Birrell if (lsum > rsum) 1926ff6d951SJohn Birrell return (DT_GREATERTHAN); 1936ff6d951SJohn Birrell 1946ff6d951SJohn Birrell /* 1956ff6d951SJohn Birrell * If they're both equal, then we will compare based on the weights at 1966ff6d951SJohn Birrell * zero. If the weights at zero are equal (or if zero is not within 1976ff6d951SJohn Birrell * the range of the linear quantization), then this will be judged a 1986ff6d951SJohn Birrell * tie and will be resolved based on the key comparison. 1996ff6d951SJohn Birrell */ 2006ff6d951SJohn Birrell lzero = dt_aggregate_lquantizedzero(lhs); 2016ff6d951SJohn Birrell rzero = dt_aggregate_lquantizedzero(rhs); 2026ff6d951SJohn Birrell 2036ff6d951SJohn Birrell if (lzero < rzero) 2046ff6d951SJohn Birrell return (DT_LESSTHAN); 2056ff6d951SJohn Birrell 2066ff6d951SJohn Birrell if (lzero > rzero) 2076ff6d951SJohn Birrell return (DT_GREATERTHAN); 2086ff6d951SJohn Birrell 2096ff6d951SJohn Birrell return (0); 2106ff6d951SJohn Birrell } 2116ff6d951SJohn Birrell 2126ff6d951SJohn Birrell static int 2136ff6d951SJohn Birrell dt_aggregate_quantizedcmp(int64_t *lhs, int64_t *rhs) 2146ff6d951SJohn Birrell { 215d9ce0144SJohn Birrell int nbuckets = DTRACE_QUANTIZE_NBUCKETS; 2166ff6d951SJohn Birrell long double ltotal = 0, rtotal = 0; 2176ff6d951SJohn Birrell int64_t lzero, rzero; 218d9ce0144SJohn Birrell uint_t i; 2196ff6d951SJohn Birrell 2206ff6d951SJohn Birrell for (i = 0; i < nbuckets; i++) { 2216ff6d951SJohn Birrell int64_t bucketval = DTRACE_QUANTIZE_BUCKETVAL(i); 2226ff6d951SJohn Birrell 2236ff6d951SJohn Birrell if (bucketval == 0) { 2246ff6d951SJohn Birrell lzero = lhs[i]; 2256ff6d951SJohn Birrell rzero = rhs[i]; 2266ff6d951SJohn Birrell } 2276ff6d951SJohn Birrell 2286ff6d951SJohn Birrell ltotal += (long double)bucketval * (long double)lhs[i]; 2296ff6d951SJohn Birrell rtotal += (long double)bucketval * (long double)rhs[i]; 2306ff6d951SJohn Birrell } 2316ff6d951SJohn Birrell 2326ff6d951SJohn Birrell if (ltotal < rtotal) 2336ff6d951SJohn Birrell return (DT_LESSTHAN); 2346ff6d951SJohn Birrell 2356ff6d951SJohn Birrell if (ltotal > rtotal) 2366ff6d951SJohn Birrell return (DT_GREATERTHAN); 2376ff6d951SJohn Birrell 2386ff6d951SJohn Birrell /* 2396ff6d951SJohn Birrell * If they're both equal, then we will compare based on the weights at 2406ff6d951SJohn Birrell * zero. If the weights at zero are equal, then this will be judged a 2416ff6d951SJohn Birrell * tie and will be resolved based on the key comparison. 2426ff6d951SJohn Birrell */ 2436ff6d951SJohn Birrell if (lzero < rzero) 2446ff6d951SJohn Birrell return (DT_LESSTHAN); 2456ff6d951SJohn Birrell 2466ff6d951SJohn Birrell if (lzero > rzero) 2476ff6d951SJohn Birrell return (DT_GREATERTHAN); 2486ff6d951SJohn Birrell 2496ff6d951SJohn Birrell return (0); 2506ff6d951SJohn Birrell } 2516ff6d951SJohn Birrell 2526ff6d951SJohn Birrell static void 2536ff6d951SJohn Birrell dt_aggregate_usym(dtrace_hdl_t *dtp, uint64_t *data) 2546ff6d951SJohn Birrell { 2556ff6d951SJohn Birrell uint64_t pid = data[0]; 2566ff6d951SJohn Birrell uint64_t *pc = &data[1]; 2576ff6d951SJohn Birrell struct ps_prochandle *P; 2586ff6d951SJohn Birrell GElf_Sym sym; 2596ff6d951SJohn Birrell 2606ff6d951SJohn Birrell if (dtp->dt_vector != NULL) 2616ff6d951SJohn Birrell return; 2626ff6d951SJohn Birrell 2636ff6d951SJohn Birrell if ((P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, 0)) == NULL) 2646ff6d951SJohn Birrell return; 2656ff6d951SJohn Birrell 2666ff6d951SJohn Birrell dt_proc_lock(dtp, P); 2676ff6d951SJohn Birrell 2686ff6d951SJohn Birrell if (Plookup_by_addr(P, *pc, NULL, 0, &sym) == 0) 2696ff6d951SJohn Birrell *pc = sym.st_value; 2706ff6d951SJohn Birrell 2716ff6d951SJohn Birrell dt_proc_unlock(dtp, P); 2726ff6d951SJohn Birrell dt_proc_release(dtp, P); 2736ff6d951SJohn Birrell } 2746ff6d951SJohn Birrell 2756ff6d951SJohn Birrell static void 2766ff6d951SJohn Birrell dt_aggregate_umod(dtrace_hdl_t *dtp, uint64_t *data) 2776ff6d951SJohn Birrell { 2786ff6d951SJohn Birrell uint64_t pid = data[0]; 2796ff6d951SJohn Birrell uint64_t *pc = &data[1]; 2806ff6d951SJohn Birrell struct ps_prochandle *P; 2816ff6d951SJohn Birrell const prmap_t *map; 2826ff6d951SJohn Birrell 2836ff6d951SJohn Birrell if (dtp->dt_vector != NULL) 2846ff6d951SJohn Birrell return; 2856ff6d951SJohn Birrell 2866ff6d951SJohn Birrell if ((P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, 0)) == NULL) 2876ff6d951SJohn Birrell return; 2886ff6d951SJohn Birrell 2896ff6d951SJohn Birrell dt_proc_lock(dtp, P); 2906ff6d951SJohn Birrell 2916ff6d951SJohn Birrell if ((map = Paddr_to_map(P, *pc)) != NULL) 2926ff6d951SJohn Birrell *pc = map->pr_vaddr; 2936ff6d951SJohn Birrell 2946ff6d951SJohn Birrell dt_proc_unlock(dtp, P); 2956ff6d951SJohn Birrell dt_proc_release(dtp, P); 2966ff6d951SJohn Birrell } 2976ff6d951SJohn Birrell 2986ff6d951SJohn Birrell static void 2996ff6d951SJohn Birrell dt_aggregate_sym(dtrace_hdl_t *dtp, uint64_t *data) 3006ff6d951SJohn Birrell { 3016ff6d951SJohn Birrell GElf_Sym sym; 3026ff6d951SJohn Birrell uint64_t *pc = data; 3036ff6d951SJohn Birrell 3046ff6d951SJohn Birrell if (dtrace_lookup_by_addr(dtp, *pc, &sym, NULL) == 0) 3056ff6d951SJohn Birrell *pc = sym.st_value; 3066ff6d951SJohn Birrell } 3076ff6d951SJohn Birrell 3086ff6d951SJohn Birrell static void 3096ff6d951SJohn Birrell dt_aggregate_mod(dtrace_hdl_t *dtp, uint64_t *data) 3106ff6d951SJohn Birrell { 3116ff6d951SJohn Birrell uint64_t *pc = data; 3126ff6d951SJohn Birrell dt_module_t *dmp; 3136ff6d951SJohn Birrell 3146ff6d951SJohn Birrell if (dtp->dt_vector != NULL) { 3156ff6d951SJohn Birrell /* 3166ff6d951SJohn Birrell * We don't have a way of just getting the module for a 3176ff6d951SJohn Birrell * vectored open, and it doesn't seem to be worth defining 3186ff6d951SJohn Birrell * one. This means that use of mod() won't get true 3196ff6d951SJohn Birrell * aggregation in the postmortem case (some modules may 3206ff6d951SJohn Birrell * appear more than once in aggregation output). It seems 3216ff6d951SJohn Birrell * unlikely that anyone will ever notice or care... 3226ff6d951SJohn Birrell */ 3236ff6d951SJohn Birrell return; 3246ff6d951SJohn Birrell } 3256ff6d951SJohn Birrell 3266ff6d951SJohn Birrell for (dmp = dt_list_next(&dtp->dt_modlist); dmp != NULL; 3276ff6d951SJohn Birrell dmp = dt_list_next(dmp)) { 3286ff6d951SJohn Birrell if (*pc - dmp->dm_text_va < dmp->dm_text_size) { 3296ff6d951SJohn Birrell *pc = dmp->dm_text_va; 3306ff6d951SJohn Birrell return; 3316ff6d951SJohn Birrell } 3326ff6d951SJohn Birrell } 3336ff6d951SJohn Birrell } 3346ff6d951SJohn Birrell 3356ff6d951SJohn Birrell static dtrace_aggvarid_t 3366ff6d951SJohn Birrell dt_aggregate_aggvarid(dt_ahashent_t *ent) 3376ff6d951SJohn Birrell { 3386ff6d951SJohn Birrell dtrace_aggdesc_t *agg = ent->dtahe_data.dtada_desc; 3396ff6d951SJohn Birrell caddr_t data = ent->dtahe_data.dtada_data; 3406ff6d951SJohn Birrell dtrace_recdesc_t *rec = agg->dtagd_rec; 3416ff6d951SJohn Birrell 3426ff6d951SJohn Birrell /* 3436ff6d951SJohn Birrell * First, we'll check the variable ID in the aggdesc. If it's valid, 3446ff6d951SJohn Birrell * we'll return it. If not, we'll use the compiler-generated ID 3456ff6d951SJohn Birrell * present as the first record. 3466ff6d951SJohn Birrell */ 3476ff6d951SJohn Birrell if (agg->dtagd_varid != DTRACE_AGGVARIDNONE) 3486ff6d951SJohn Birrell return (agg->dtagd_varid); 3496ff6d951SJohn Birrell 3506ff6d951SJohn Birrell agg->dtagd_varid = *((dtrace_aggvarid_t *)(uintptr_t)(data + 3516ff6d951SJohn Birrell rec->dtrd_offset)); 3526ff6d951SJohn Birrell 3536ff6d951SJohn Birrell return (agg->dtagd_varid); 3546ff6d951SJohn Birrell } 3556ff6d951SJohn Birrell 3566ff6d951SJohn Birrell 3576ff6d951SJohn Birrell static int 3586ff6d951SJohn Birrell dt_aggregate_snap_cpu(dtrace_hdl_t *dtp, processorid_t cpu) 3596ff6d951SJohn Birrell { 3606ff6d951SJohn Birrell dtrace_epid_t id; 3616ff6d951SJohn Birrell uint64_t hashval; 3626ff6d951SJohn Birrell size_t offs, roffs, size, ndx; 3636ff6d951SJohn Birrell int i, j, rval; 3646ff6d951SJohn Birrell caddr_t addr, data; 3656ff6d951SJohn Birrell dtrace_recdesc_t *rec; 3666ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 3676ff6d951SJohn Birrell dtrace_aggdesc_t *agg; 3686ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 3696ff6d951SJohn Birrell dt_ahashent_t *h; 3706ff6d951SJohn Birrell dtrace_bufdesc_t b = agp->dtat_buf, *buf = &b; 3716ff6d951SJohn Birrell dtrace_aggdata_t *aggdata; 3726ff6d951SJohn Birrell int flags = agp->dtat_flags; 3736ff6d951SJohn Birrell 3746ff6d951SJohn Birrell buf->dtbd_cpu = cpu; 3756ff6d951SJohn Birrell 376d9ce0144SJohn Birrell #if defined(sun) 3776ff6d951SJohn Birrell if (dt_ioctl(dtp, DTRACEIOC_AGGSNAP, buf) == -1) { 378d9ce0144SJohn Birrell #else 379d9ce0144SJohn Birrell if (dt_ioctl(dtp, DTRACEIOC_AGGSNAP, &buf) == -1) { 380d9ce0144SJohn Birrell #endif 3816ff6d951SJohn Birrell if (errno == ENOENT) { 3826ff6d951SJohn Birrell /* 3836ff6d951SJohn Birrell * If that failed with ENOENT, it may be because the 3846ff6d951SJohn Birrell * CPU was unconfigured. This is okay; we'll just 3856ff6d951SJohn Birrell * do nothing but return success. 3866ff6d951SJohn Birrell */ 3876ff6d951SJohn Birrell return (0); 3886ff6d951SJohn Birrell } 3896ff6d951SJohn Birrell 3906ff6d951SJohn Birrell return (dt_set_errno(dtp, errno)); 3916ff6d951SJohn Birrell } 3926ff6d951SJohn Birrell 3936ff6d951SJohn Birrell if (buf->dtbd_drops != 0) { 3946ff6d951SJohn Birrell if (dt_handle_cpudrop(dtp, cpu, 3956ff6d951SJohn Birrell DTRACEDROP_AGGREGATION, buf->dtbd_drops) == -1) 3966ff6d951SJohn Birrell return (-1); 3976ff6d951SJohn Birrell } 3986ff6d951SJohn Birrell 3996ff6d951SJohn Birrell if (buf->dtbd_size == 0) 4006ff6d951SJohn Birrell return (0); 4016ff6d951SJohn Birrell 4026ff6d951SJohn Birrell if (hash->dtah_hash == NULL) { 4036ff6d951SJohn Birrell size_t size; 4046ff6d951SJohn Birrell 4056ff6d951SJohn Birrell hash->dtah_size = DTRACE_AHASHSIZE; 4066ff6d951SJohn Birrell size = hash->dtah_size * sizeof (dt_ahashent_t *); 4076ff6d951SJohn Birrell 4086ff6d951SJohn Birrell if ((hash->dtah_hash = malloc(size)) == NULL) 4096ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 4106ff6d951SJohn Birrell 4116ff6d951SJohn Birrell bzero(hash->dtah_hash, size); 4126ff6d951SJohn Birrell } 4136ff6d951SJohn Birrell 4146ff6d951SJohn Birrell for (offs = 0; offs < buf->dtbd_size; ) { 4156ff6d951SJohn Birrell /* 4166ff6d951SJohn Birrell * We're guaranteed to have an ID. 4176ff6d951SJohn Birrell */ 4186ff6d951SJohn Birrell id = *((dtrace_epid_t *)((uintptr_t)buf->dtbd_data + 4196ff6d951SJohn Birrell (uintptr_t)offs)); 4206ff6d951SJohn Birrell 4216ff6d951SJohn Birrell if (id == DTRACE_AGGIDNONE) { 4226ff6d951SJohn Birrell /* 4236ff6d951SJohn Birrell * This is filler to assure proper alignment of the 4246ff6d951SJohn Birrell * next record; we simply ignore it. 4256ff6d951SJohn Birrell */ 4266ff6d951SJohn Birrell offs += sizeof (id); 4276ff6d951SJohn Birrell continue; 4286ff6d951SJohn Birrell } 4296ff6d951SJohn Birrell 4306ff6d951SJohn Birrell if ((rval = dt_aggid_lookup(dtp, id, &agg)) != 0) 4316ff6d951SJohn Birrell return (rval); 4326ff6d951SJohn Birrell 4336ff6d951SJohn Birrell addr = buf->dtbd_data + offs; 4346ff6d951SJohn Birrell size = agg->dtagd_size; 4356ff6d951SJohn Birrell hashval = 0; 4366ff6d951SJohn Birrell 4376ff6d951SJohn Birrell for (j = 0; j < agg->dtagd_nrecs - 1; j++) { 4386ff6d951SJohn Birrell rec = &agg->dtagd_rec[j]; 4396ff6d951SJohn Birrell roffs = rec->dtrd_offset; 4406ff6d951SJohn Birrell 4416ff6d951SJohn Birrell switch (rec->dtrd_action) { 4426ff6d951SJohn Birrell case DTRACEACT_USYM: 4436ff6d951SJohn Birrell dt_aggregate_usym(dtp, 4446ff6d951SJohn Birrell /* LINTED - alignment */ 4456ff6d951SJohn Birrell (uint64_t *)&addr[roffs]); 4466ff6d951SJohn Birrell break; 4476ff6d951SJohn Birrell 4486ff6d951SJohn Birrell case DTRACEACT_UMOD: 4496ff6d951SJohn Birrell dt_aggregate_umod(dtp, 4506ff6d951SJohn Birrell /* LINTED - alignment */ 4516ff6d951SJohn Birrell (uint64_t *)&addr[roffs]); 4526ff6d951SJohn Birrell break; 4536ff6d951SJohn Birrell 4546ff6d951SJohn Birrell case DTRACEACT_SYM: 4556ff6d951SJohn Birrell /* LINTED - alignment */ 4566ff6d951SJohn Birrell dt_aggregate_sym(dtp, (uint64_t *)&addr[roffs]); 4576ff6d951SJohn Birrell break; 4586ff6d951SJohn Birrell 4596ff6d951SJohn Birrell case DTRACEACT_MOD: 4606ff6d951SJohn Birrell /* LINTED - alignment */ 4616ff6d951SJohn Birrell dt_aggregate_mod(dtp, (uint64_t *)&addr[roffs]); 4626ff6d951SJohn Birrell break; 4636ff6d951SJohn Birrell 4646ff6d951SJohn Birrell default: 4656ff6d951SJohn Birrell break; 4666ff6d951SJohn Birrell } 4676ff6d951SJohn Birrell 4686ff6d951SJohn Birrell for (i = 0; i < rec->dtrd_size; i++) 4696ff6d951SJohn Birrell hashval += addr[roffs + i]; 4706ff6d951SJohn Birrell } 4716ff6d951SJohn Birrell 4726ff6d951SJohn Birrell ndx = hashval % hash->dtah_size; 4736ff6d951SJohn Birrell 4746ff6d951SJohn Birrell for (h = hash->dtah_hash[ndx]; h != NULL; h = h->dtahe_next) { 4756ff6d951SJohn Birrell if (h->dtahe_hashval != hashval) 4766ff6d951SJohn Birrell continue; 4776ff6d951SJohn Birrell 4786ff6d951SJohn Birrell if (h->dtahe_size != size) 4796ff6d951SJohn Birrell continue; 4806ff6d951SJohn Birrell 4816ff6d951SJohn Birrell aggdata = &h->dtahe_data; 4826ff6d951SJohn Birrell data = aggdata->dtada_data; 4836ff6d951SJohn Birrell 4846ff6d951SJohn Birrell for (j = 0; j < agg->dtagd_nrecs - 1; j++) { 4856ff6d951SJohn Birrell rec = &agg->dtagd_rec[j]; 4866ff6d951SJohn Birrell roffs = rec->dtrd_offset; 4876ff6d951SJohn Birrell 4886ff6d951SJohn Birrell for (i = 0; i < rec->dtrd_size; i++) 4896ff6d951SJohn Birrell if (addr[roffs + i] != data[roffs + i]) 4906ff6d951SJohn Birrell goto hashnext; 4916ff6d951SJohn Birrell } 4926ff6d951SJohn Birrell 4936ff6d951SJohn Birrell /* 4946ff6d951SJohn Birrell * We found it. Now we need to apply the aggregating 4956ff6d951SJohn Birrell * action on the data here. 4966ff6d951SJohn Birrell */ 4976ff6d951SJohn Birrell rec = &agg->dtagd_rec[agg->dtagd_nrecs - 1]; 4986ff6d951SJohn Birrell roffs = rec->dtrd_offset; 4996ff6d951SJohn Birrell /* LINTED - alignment */ 5006ff6d951SJohn Birrell h->dtahe_aggregate((int64_t *)&data[roffs], 5016ff6d951SJohn Birrell /* LINTED - alignment */ 5026ff6d951SJohn Birrell (int64_t *)&addr[roffs], rec->dtrd_size); 5036ff6d951SJohn Birrell 5046ff6d951SJohn Birrell /* 5056ff6d951SJohn Birrell * If we're keeping per CPU data, apply the aggregating 5066ff6d951SJohn Birrell * action there as well. 5076ff6d951SJohn Birrell */ 5086ff6d951SJohn Birrell if (aggdata->dtada_percpu != NULL) { 5096ff6d951SJohn Birrell data = aggdata->dtada_percpu[cpu]; 5106ff6d951SJohn Birrell 5116ff6d951SJohn Birrell /* LINTED - alignment */ 5126ff6d951SJohn Birrell h->dtahe_aggregate((int64_t *)data, 5136ff6d951SJohn Birrell /* LINTED - alignment */ 5146ff6d951SJohn Birrell (int64_t *)&addr[roffs], rec->dtrd_size); 5156ff6d951SJohn Birrell } 5166ff6d951SJohn Birrell 5176ff6d951SJohn Birrell goto bufnext; 5186ff6d951SJohn Birrell hashnext: 5196ff6d951SJohn Birrell continue; 5206ff6d951SJohn Birrell } 5216ff6d951SJohn Birrell 5226ff6d951SJohn Birrell /* 5236ff6d951SJohn Birrell * If we're here, we couldn't find an entry for this record. 5246ff6d951SJohn Birrell */ 5256ff6d951SJohn Birrell if ((h = malloc(sizeof (dt_ahashent_t))) == NULL) 5266ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 5276ff6d951SJohn Birrell bzero(h, sizeof (dt_ahashent_t)); 5286ff6d951SJohn Birrell aggdata = &h->dtahe_data; 5296ff6d951SJohn Birrell 5306ff6d951SJohn Birrell if ((aggdata->dtada_data = malloc(size)) == NULL) { 5316ff6d951SJohn Birrell free(h); 5326ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 5336ff6d951SJohn Birrell } 5346ff6d951SJohn Birrell 5356ff6d951SJohn Birrell bcopy(addr, aggdata->dtada_data, size); 5366ff6d951SJohn Birrell aggdata->dtada_size = size; 5376ff6d951SJohn Birrell aggdata->dtada_desc = agg; 5386ff6d951SJohn Birrell aggdata->dtada_handle = dtp; 5396ff6d951SJohn Birrell (void) dt_epid_lookup(dtp, agg->dtagd_epid, 5406ff6d951SJohn Birrell &aggdata->dtada_edesc, &aggdata->dtada_pdesc); 5416ff6d951SJohn Birrell aggdata->dtada_normal = 1; 5426ff6d951SJohn Birrell 5436ff6d951SJohn Birrell h->dtahe_hashval = hashval; 5446ff6d951SJohn Birrell h->dtahe_size = size; 5456ff6d951SJohn Birrell (void) dt_aggregate_aggvarid(h); 5466ff6d951SJohn Birrell 5476ff6d951SJohn Birrell rec = &agg->dtagd_rec[agg->dtagd_nrecs - 1]; 5486ff6d951SJohn Birrell 5496ff6d951SJohn Birrell if (flags & DTRACE_A_PERCPU) { 5506ff6d951SJohn Birrell int max_cpus = agp->dtat_maxcpu; 5516ff6d951SJohn Birrell caddr_t *percpu = malloc(max_cpus * sizeof (caddr_t)); 5526ff6d951SJohn Birrell 5536ff6d951SJohn Birrell if (percpu == NULL) { 5546ff6d951SJohn Birrell free(aggdata->dtada_data); 5556ff6d951SJohn Birrell free(h); 5566ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 5576ff6d951SJohn Birrell } 5586ff6d951SJohn Birrell 5596ff6d951SJohn Birrell for (j = 0; j < max_cpus; j++) { 5606ff6d951SJohn Birrell percpu[j] = malloc(rec->dtrd_size); 5616ff6d951SJohn Birrell 5626ff6d951SJohn Birrell if (percpu[j] == NULL) { 5636ff6d951SJohn Birrell while (--j >= 0) 5646ff6d951SJohn Birrell free(percpu[j]); 5656ff6d951SJohn Birrell 5666ff6d951SJohn Birrell free(aggdata->dtada_data); 5676ff6d951SJohn Birrell free(h); 5686ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 5696ff6d951SJohn Birrell } 5706ff6d951SJohn Birrell 5716ff6d951SJohn Birrell if (j == cpu) { 5726ff6d951SJohn Birrell bcopy(&addr[rec->dtrd_offset], 5736ff6d951SJohn Birrell percpu[j], rec->dtrd_size); 5746ff6d951SJohn Birrell } else { 5756ff6d951SJohn Birrell bzero(percpu[j], rec->dtrd_size); 5766ff6d951SJohn Birrell } 5776ff6d951SJohn Birrell } 5786ff6d951SJohn Birrell 5796ff6d951SJohn Birrell aggdata->dtada_percpu = percpu; 5806ff6d951SJohn Birrell } 5816ff6d951SJohn Birrell 5826ff6d951SJohn Birrell switch (rec->dtrd_action) { 5836ff6d951SJohn Birrell case DTRACEAGG_MIN: 5846ff6d951SJohn Birrell h->dtahe_aggregate = dt_aggregate_min; 5856ff6d951SJohn Birrell break; 5866ff6d951SJohn Birrell 5876ff6d951SJohn Birrell case DTRACEAGG_MAX: 5886ff6d951SJohn Birrell h->dtahe_aggregate = dt_aggregate_max; 5896ff6d951SJohn Birrell break; 5906ff6d951SJohn Birrell 5916ff6d951SJohn Birrell case DTRACEAGG_LQUANTIZE: 5926ff6d951SJohn Birrell h->dtahe_aggregate = dt_aggregate_lquantize; 5936ff6d951SJohn Birrell break; 5946ff6d951SJohn Birrell 5956ff6d951SJohn Birrell case DTRACEAGG_COUNT: 5966ff6d951SJohn Birrell case DTRACEAGG_SUM: 5976ff6d951SJohn Birrell case DTRACEAGG_AVG: 5986ff6d951SJohn Birrell case DTRACEAGG_STDDEV: 5996ff6d951SJohn Birrell case DTRACEAGG_QUANTIZE: 6006ff6d951SJohn Birrell h->dtahe_aggregate = dt_aggregate_count; 6016ff6d951SJohn Birrell break; 6026ff6d951SJohn Birrell 6036ff6d951SJohn Birrell default: 6046ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_BADAGG)); 6056ff6d951SJohn Birrell } 6066ff6d951SJohn Birrell 6076ff6d951SJohn Birrell if (hash->dtah_hash[ndx] != NULL) 6086ff6d951SJohn Birrell hash->dtah_hash[ndx]->dtahe_prev = h; 6096ff6d951SJohn Birrell 6106ff6d951SJohn Birrell h->dtahe_next = hash->dtah_hash[ndx]; 6116ff6d951SJohn Birrell hash->dtah_hash[ndx] = h; 6126ff6d951SJohn Birrell 6136ff6d951SJohn Birrell if (hash->dtah_all != NULL) 6146ff6d951SJohn Birrell hash->dtah_all->dtahe_prevall = h; 6156ff6d951SJohn Birrell 6166ff6d951SJohn Birrell h->dtahe_nextall = hash->dtah_all; 6176ff6d951SJohn Birrell hash->dtah_all = h; 6186ff6d951SJohn Birrell bufnext: 6196ff6d951SJohn Birrell offs += agg->dtagd_size; 6206ff6d951SJohn Birrell } 6216ff6d951SJohn Birrell 6226ff6d951SJohn Birrell return (0); 6236ff6d951SJohn Birrell } 6246ff6d951SJohn Birrell 6256ff6d951SJohn Birrell int 6266ff6d951SJohn Birrell dtrace_aggregate_snap(dtrace_hdl_t *dtp) 6276ff6d951SJohn Birrell { 6286ff6d951SJohn Birrell int i, rval; 6296ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 6306ff6d951SJohn Birrell hrtime_t now = gethrtime(); 6316ff6d951SJohn Birrell dtrace_optval_t interval = dtp->dt_options[DTRACEOPT_AGGRATE]; 6326ff6d951SJohn Birrell 6336ff6d951SJohn Birrell if (dtp->dt_lastagg != 0) { 6346ff6d951SJohn Birrell if (now - dtp->dt_lastagg < interval) 6356ff6d951SJohn Birrell return (0); 6366ff6d951SJohn Birrell 6376ff6d951SJohn Birrell dtp->dt_lastagg += interval; 6386ff6d951SJohn Birrell } else { 6396ff6d951SJohn Birrell dtp->dt_lastagg = now; 6406ff6d951SJohn Birrell } 6416ff6d951SJohn Birrell 6426ff6d951SJohn Birrell if (!dtp->dt_active) 6436ff6d951SJohn Birrell return (dt_set_errno(dtp, EINVAL)); 6446ff6d951SJohn Birrell 6456ff6d951SJohn Birrell if (agp->dtat_buf.dtbd_size == 0) 6466ff6d951SJohn Birrell return (0); 6476ff6d951SJohn Birrell 6486ff6d951SJohn Birrell for (i = 0; i < agp->dtat_ncpus; i++) { 649d9ce0144SJohn Birrell if ((rval = dt_aggregate_snap_cpu(dtp, agp->dtat_cpus[i]))) 6506ff6d951SJohn Birrell return (rval); 6516ff6d951SJohn Birrell } 6526ff6d951SJohn Birrell 6536ff6d951SJohn Birrell return (0); 6546ff6d951SJohn Birrell } 6556ff6d951SJohn Birrell 6566ff6d951SJohn Birrell static int 6576ff6d951SJohn Birrell dt_aggregate_hashcmp(const void *lhs, const void *rhs) 6586ff6d951SJohn Birrell { 6596ff6d951SJohn Birrell dt_ahashent_t *lh = *((dt_ahashent_t **)lhs); 6606ff6d951SJohn Birrell dt_ahashent_t *rh = *((dt_ahashent_t **)rhs); 6616ff6d951SJohn Birrell dtrace_aggdesc_t *lagg = lh->dtahe_data.dtada_desc; 6626ff6d951SJohn Birrell dtrace_aggdesc_t *ragg = rh->dtahe_data.dtada_desc; 6636ff6d951SJohn Birrell 6646ff6d951SJohn Birrell if (lagg->dtagd_nrecs < ragg->dtagd_nrecs) 6656ff6d951SJohn Birrell return (DT_LESSTHAN); 6666ff6d951SJohn Birrell 6676ff6d951SJohn Birrell if (lagg->dtagd_nrecs > ragg->dtagd_nrecs) 6686ff6d951SJohn Birrell return (DT_GREATERTHAN); 6696ff6d951SJohn Birrell 6706ff6d951SJohn Birrell return (0); 6716ff6d951SJohn Birrell } 6726ff6d951SJohn Birrell 6736ff6d951SJohn Birrell static int 6746ff6d951SJohn Birrell dt_aggregate_varcmp(const void *lhs, const void *rhs) 6756ff6d951SJohn Birrell { 6766ff6d951SJohn Birrell dt_ahashent_t *lh = *((dt_ahashent_t **)lhs); 6776ff6d951SJohn Birrell dt_ahashent_t *rh = *((dt_ahashent_t **)rhs); 6786ff6d951SJohn Birrell dtrace_aggvarid_t lid, rid; 6796ff6d951SJohn Birrell 6806ff6d951SJohn Birrell lid = dt_aggregate_aggvarid(lh); 6816ff6d951SJohn Birrell rid = dt_aggregate_aggvarid(rh); 6826ff6d951SJohn Birrell 6836ff6d951SJohn Birrell if (lid < rid) 6846ff6d951SJohn Birrell return (DT_LESSTHAN); 6856ff6d951SJohn Birrell 6866ff6d951SJohn Birrell if (lid > rid) 6876ff6d951SJohn Birrell return (DT_GREATERTHAN); 6886ff6d951SJohn Birrell 6896ff6d951SJohn Birrell return (0); 6906ff6d951SJohn Birrell } 6916ff6d951SJohn Birrell 6926ff6d951SJohn Birrell static int 6936ff6d951SJohn Birrell dt_aggregate_keycmp(const void *lhs, const void *rhs) 6946ff6d951SJohn Birrell { 6956ff6d951SJohn Birrell dt_ahashent_t *lh = *((dt_ahashent_t **)lhs); 6966ff6d951SJohn Birrell dt_ahashent_t *rh = *((dt_ahashent_t **)rhs); 6976ff6d951SJohn Birrell dtrace_aggdesc_t *lagg = lh->dtahe_data.dtada_desc; 6986ff6d951SJohn Birrell dtrace_aggdesc_t *ragg = rh->dtahe_data.dtada_desc; 6996ff6d951SJohn Birrell dtrace_recdesc_t *lrec, *rrec; 7006ff6d951SJohn Birrell char *ldata, *rdata; 7016ff6d951SJohn Birrell int rval, i, j, keypos, nrecs; 7026ff6d951SJohn Birrell 7036ff6d951SJohn Birrell if ((rval = dt_aggregate_hashcmp(lhs, rhs)) != 0) 7046ff6d951SJohn Birrell return (rval); 7056ff6d951SJohn Birrell 7066ff6d951SJohn Birrell nrecs = lagg->dtagd_nrecs - 1; 7076ff6d951SJohn Birrell assert(nrecs == ragg->dtagd_nrecs - 1); 7086ff6d951SJohn Birrell 7096ff6d951SJohn Birrell keypos = dt_keypos + 1 >= nrecs ? 0 : dt_keypos; 7106ff6d951SJohn Birrell 7116ff6d951SJohn Birrell for (i = 1; i < nrecs; i++) { 7126ff6d951SJohn Birrell uint64_t lval, rval; 7136ff6d951SJohn Birrell int ndx = i + keypos; 7146ff6d951SJohn Birrell 7156ff6d951SJohn Birrell if (ndx >= nrecs) 7166ff6d951SJohn Birrell ndx = ndx - nrecs + 1; 7176ff6d951SJohn Birrell 7186ff6d951SJohn Birrell lrec = &lagg->dtagd_rec[ndx]; 7196ff6d951SJohn Birrell rrec = &ragg->dtagd_rec[ndx]; 7206ff6d951SJohn Birrell 7216ff6d951SJohn Birrell ldata = lh->dtahe_data.dtada_data + lrec->dtrd_offset; 7226ff6d951SJohn Birrell rdata = rh->dtahe_data.dtada_data + rrec->dtrd_offset; 7236ff6d951SJohn Birrell 7246ff6d951SJohn Birrell if (lrec->dtrd_size < rrec->dtrd_size) 7256ff6d951SJohn Birrell return (DT_LESSTHAN); 7266ff6d951SJohn Birrell 7276ff6d951SJohn Birrell if (lrec->dtrd_size > rrec->dtrd_size) 7286ff6d951SJohn Birrell return (DT_GREATERTHAN); 7296ff6d951SJohn Birrell 7306ff6d951SJohn Birrell switch (lrec->dtrd_size) { 7316ff6d951SJohn Birrell case sizeof (uint64_t): 7326ff6d951SJohn Birrell /* LINTED - alignment */ 7336ff6d951SJohn Birrell lval = *((uint64_t *)ldata); 7346ff6d951SJohn Birrell /* LINTED - alignment */ 7356ff6d951SJohn Birrell rval = *((uint64_t *)rdata); 7366ff6d951SJohn Birrell break; 7376ff6d951SJohn Birrell 7386ff6d951SJohn Birrell case sizeof (uint32_t): 7396ff6d951SJohn Birrell /* LINTED - alignment */ 7406ff6d951SJohn Birrell lval = *((uint32_t *)ldata); 7416ff6d951SJohn Birrell /* LINTED - alignment */ 7426ff6d951SJohn Birrell rval = *((uint32_t *)rdata); 7436ff6d951SJohn Birrell break; 7446ff6d951SJohn Birrell 7456ff6d951SJohn Birrell case sizeof (uint16_t): 7466ff6d951SJohn Birrell /* LINTED - alignment */ 7476ff6d951SJohn Birrell lval = *((uint16_t *)ldata); 7486ff6d951SJohn Birrell /* LINTED - alignment */ 7496ff6d951SJohn Birrell rval = *((uint16_t *)rdata); 7506ff6d951SJohn Birrell break; 7516ff6d951SJohn Birrell 7526ff6d951SJohn Birrell case sizeof (uint8_t): 7536ff6d951SJohn Birrell lval = *((uint8_t *)ldata); 7546ff6d951SJohn Birrell rval = *((uint8_t *)rdata); 7556ff6d951SJohn Birrell break; 7566ff6d951SJohn Birrell 7576ff6d951SJohn Birrell default: 7586ff6d951SJohn Birrell switch (lrec->dtrd_action) { 7596ff6d951SJohn Birrell case DTRACEACT_UMOD: 7606ff6d951SJohn Birrell case DTRACEACT_UADDR: 7616ff6d951SJohn Birrell case DTRACEACT_USYM: 7626ff6d951SJohn Birrell for (j = 0; j < 2; j++) { 7636ff6d951SJohn Birrell /* LINTED - alignment */ 7646ff6d951SJohn Birrell lval = ((uint64_t *)ldata)[j]; 7656ff6d951SJohn Birrell /* LINTED - alignment */ 7666ff6d951SJohn Birrell rval = ((uint64_t *)rdata)[j]; 7676ff6d951SJohn Birrell 7686ff6d951SJohn Birrell if (lval < rval) 7696ff6d951SJohn Birrell return (DT_LESSTHAN); 7706ff6d951SJohn Birrell 7716ff6d951SJohn Birrell if (lval > rval) 7726ff6d951SJohn Birrell return (DT_GREATERTHAN); 7736ff6d951SJohn Birrell } 7746ff6d951SJohn Birrell 7756ff6d951SJohn Birrell break; 7766ff6d951SJohn Birrell 7776ff6d951SJohn Birrell default: 7786ff6d951SJohn Birrell for (j = 0; j < lrec->dtrd_size; j++) { 7796ff6d951SJohn Birrell lval = ((uint8_t *)ldata)[j]; 7806ff6d951SJohn Birrell rval = ((uint8_t *)rdata)[j]; 7816ff6d951SJohn Birrell 7826ff6d951SJohn Birrell if (lval < rval) 7836ff6d951SJohn Birrell return (DT_LESSTHAN); 7846ff6d951SJohn Birrell 7856ff6d951SJohn Birrell if (lval > rval) 7866ff6d951SJohn Birrell return (DT_GREATERTHAN); 7876ff6d951SJohn Birrell } 7886ff6d951SJohn Birrell } 7896ff6d951SJohn Birrell 7906ff6d951SJohn Birrell continue; 7916ff6d951SJohn Birrell } 7926ff6d951SJohn Birrell 7936ff6d951SJohn Birrell if (lval < rval) 7946ff6d951SJohn Birrell return (DT_LESSTHAN); 7956ff6d951SJohn Birrell 7966ff6d951SJohn Birrell if (lval > rval) 7976ff6d951SJohn Birrell return (DT_GREATERTHAN); 7986ff6d951SJohn Birrell } 7996ff6d951SJohn Birrell 8006ff6d951SJohn Birrell return (0); 8016ff6d951SJohn Birrell } 8026ff6d951SJohn Birrell 8036ff6d951SJohn Birrell static int 8046ff6d951SJohn Birrell dt_aggregate_valcmp(const void *lhs, const void *rhs) 8056ff6d951SJohn Birrell { 8066ff6d951SJohn Birrell dt_ahashent_t *lh = *((dt_ahashent_t **)lhs); 8076ff6d951SJohn Birrell dt_ahashent_t *rh = *((dt_ahashent_t **)rhs); 8086ff6d951SJohn Birrell dtrace_aggdesc_t *lagg = lh->dtahe_data.dtada_desc; 8096ff6d951SJohn Birrell dtrace_aggdesc_t *ragg = rh->dtahe_data.dtada_desc; 8106ff6d951SJohn Birrell caddr_t ldata = lh->dtahe_data.dtada_data; 8116ff6d951SJohn Birrell caddr_t rdata = rh->dtahe_data.dtada_data; 8126ff6d951SJohn Birrell dtrace_recdesc_t *lrec, *rrec; 8136ff6d951SJohn Birrell int64_t *laddr, *raddr; 8146ff6d951SJohn Birrell int rval, i; 8156ff6d951SJohn Birrell 8166ff6d951SJohn Birrell if ((rval = dt_aggregate_hashcmp(lhs, rhs)) != 0) 8176ff6d951SJohn Birrell return (rval); 8186ff6d951SJohn Birrell 8196ff6d951SJohn Birrell if (lagg->dtagd_nrecs > ragg->dtagd_nrecs) 8206ff6d951SJohn Birrell return (DT_GREATERTHAN); 8216ff6d951SJohn Birrell 8226ff6d951SJohn Birrell if (lagg->dtagd_nrecs < ragg->dtagd_nrecs) 8236ff6d951SJohn Birrell return (DT_LESSTHAN); 8246ff6d951SJohn Birrell 8256ff6d951SJohn Birrell for (i = 0; i < lagg->dtagd_nrecs; i++) { 8266ff6d951SJohn Birrell lrec = &lagg->dtagd_rec[i]; 8276ff6d951SJohn Birrell rrec = &ragg->dtagd_rec[i]; 8286ff6d951SJohn Birrell 8296ff6d951SJohn Birrell if (lrec->dtrd_offset < rrec->dtrd_offset) 8306ff6d951SJohn Birrell return (DT_LESSTHAN); 8316ff6d951SJohn Birrell 8326ff6d951SJohn Birrell if (lrec->dtrd_offset > rrec->dtrd_offset) 8336ff6d951SJohn Birrell return (DT_GREATERTHAN); 8346ff6d951SJohn Birrell 8356ff6d951SJohn Birrell if (lrec->dtrd_action < rrec->dtrd_action) 8366ff6d951SJohn Birrell return (DT_LESSTHAN); 8376ff6d951SJohn Birrell 8386ff6d951SJohn Birrell if (lrec->dtrd_action > rrec->dtrd_action) 8396ff6d951SJohn Birrell return (DT_GREATERTHAN); 8406ff6d951SJohn Birrell } 8416ff6d951SJohn Birrell 8426ff6d951SJohn Birrell laddr = (int64_t *)(uintptr_t)(ldata + lrec->dtrd_offset); 8436ff6d951SJohn Birrell raddr = (int64_t *)(uintptr_t)(rdata + rrec->dtrd_offset); 8446ff6d951SJohn Birrell 8456ff6d951SJohn Birrell switch (lrec->dtrd_action) { 8466ff6d951SJohn Birrell case DTRACEAGG_AVG: 8476ff6d951SJohn Birrell rval = dt_aggregate_averagecmp(laddr, raddr); 8486ff6d951SJohn Birrell break; 8496ff6d951SJohn Birrell 8506ff6d951SJohn Birrell case DTRACEAGG_STDDEV: 8516ff6d951SJohn Birrell rval = dt_aggregate_stddevcmp(laddr, raddr); 8526ff6d951SJohn Birrell break; 8536ff6d951SJohn Birrell 8546ff6d951SJohn Birrell case DTRACEAGG_QUANTIZE: 8556ff6d951SJohn Birrell rval = dt_aggregate_quantizedcmp(laddr, raddr); 8566ff6d951SJohn Birrell break; 8576ff6d951SJohn Birrell 8586ff6d951SJohn Birrell case DTRACEAGG_LQUANTIZE: 8596ff6d951SJohn Birrell rval = dt_aggregate_lquantizedcmp(laddr, raddr); 8606ff6d951SJohn Birrell break; 8616ff6d951SJohn Birrell 8626ff6d951SJohn Birrell case DTRACEAGG_COUNT: 8636ff6d951SJohn Birrell case DTRACEAGG_SUM: 8646ff6d951SJohn Birrell case DTRACEAGG_MIN: 8656ff6d951SJohn Birrell case DTRACEAGG_MAX: 8666ff6d951SJohn Birrell rval = dt_aggregate_countcmp(laddr, raddr); 8676ff6d951SJohn Birrell break; 8686ff6d951SJohn Birrell 8696ff6d951SJohn Birrell default: 8706ff6d951SJohn Birrell assert(0); 8716ff6d951SJohn Birrell } 8726ff6d951SJohn Birrell 8736ff6d951SJohn Birrell return (rval); 8746ff6d951SJohn Birrell } 8756ff6d951SJohn Birrell 8766ff6d951SJohn Birrell static int 8776ff6d951SJohn Birrell dt_aggregate_valkeycmp(const void *lhs, const void *rhs) 8786ff6d951SJohn Birrell { 8796ff6d951SJohn Birrell int rval; 8806ff6d951SJohn Birrell 8816ff6d951SJohn Birrell if ((rval = dt_aggregate_valcmp(lhs, rhs)) != 0) 8826ff6d951SJohn Birrell return (rval); 8836ff6d951SJohn Birrell 8846ff6d951SJohn Birrell /* 8856ff6d951SJohn Birrell * If we're here, the values for the two aggregation elements are 8866ff6d951SJohn Birrell * equal. We already know that the key layout is the same for the two 8876ff6d951SJohn Birrell * elements; we must now compare the keys themselves as a tie-breaker. 8886ff6d951SJohn Birrell */ 8896ff6d951SJohn Birrell return (dt_aggregate_keycmp(lhs, rhs)); 8906ff6d951SJohn Birrell } 8916ff6d951SJohn Birrell 8926ff6d951SJohn Birrell static int 8936ff6d951SJohn Birrell dt_aggregate_keyvarcmp(const void *lhs, const void *rhs) 8946ff6d951SJohn Birrell { 8956ff6d951SJohn Birrell int rval; 8966ff6d951SJohn Birrell 8976ff6d951SJohn Birrell if ((rval = dt_aggregate_keycmp(lhs, rhs)) != 0) 8986ff6d951SJohn Birrell return (rval); 8996ff6d951SJohn Birrell 9006ff6d951SJohn Birrell return (dt_aggregate_varcmp(lhs, rhs)); 9016ff6d951SJohn Birrell } 9026ff6d951SJohn Birrell 9036ff6d951SJohn Birrell static int 9046ff6d951SJohn Birrell dt_aggregate_varkeycmp(const void *lhs, const void *rhs) 9056ff6d951SJohn Birrell { 9066ff6d951SJohn Birrell int rval; 9076ff6d951SJohn Birrell 9086ff6d951SJohn Birrell if ((rval = dt_aggregate_varcmp(lhs, rhs)) != 0) 9096ff6d951SJohn Birrell return (rval); 9106ff6d951SJohn Birrell 9116ff6d951SJohn Birrell return (dt_aggregate_keycmp(lhs, rhs)); 9126ff6d951SJohn Birrell } 9136ff6d951SJohn Birrell 9146ff6d951SJohn Birrell static int 9156ff6d951SJohn Birrell dt_aggregate_valvarcmp(const void *lhs, const void *rhs) 9166ff6d951SJohn Birrell { 9176ff6d951SJohn Birrell int rval; 9186ff6d951SJohn Birrell 9196ff6d951SJohn Birrell if ((rval = dt_aggregate_valkeycmp(lhs, rhs)) != 0) 9206ff6d951SJohn Birrell return (rval); 9216ff6d951SJohn Birrell 9226ff6d951SJohn Birrell return (dt_aggregate_varcmp(lhs, rhs)); 9236ff6d951SJohn Birrell } 9246ff6d951SJohn Birrell 9256ff6d951SJohn Birrell static int 9266ff6d951SJohn Birrell dt_aggregate_varvalcmp(const void *lhs, const void *rhs) 9276ff6d951SJohn Birrell { 9286ff6d951SJohn Birrell int rval; 9296ff6d951SJohn Birrell 9306ff6d951SJohn Birrell if ((rval = dt_aggregate_varcmp(lhs, rhs)) != 0) 9316ff6d951SJohn Birrell return (rval); 9326ff6d951SJohn Birrell 9336ff6d951SJohn Birrell return (dt_aggregate_valkeycmp(lhs, rhs)); 9346ff6d951SJohn Birrell } 9356ff6d951SJohn Birrell 9366ff6d951SJohn Birrell static int 9376ff6d951SJohn Birrell dt_aggregate_keyvarrevcmp(const void *lhs, const void *rhs) 9386ff6d951SJohn Birrell { 9396ff6d951SJohn Birrell return (dt_aggregate_keyvarcmp(rhs, lhs)); 9406ff6d951SJohn Birrell } 9416ff6d951SJohn Birrell 9426ff6d951SJohn Birrell static int 9436ff6d951SJohn Birrell dt_aggregate_varkeyrevcmp(const void *lhs, const void *rhs) 9446ff6d951SJohn Birrell { 9456ff6d951SJohn Birrell return (dt_aggregate_varkeycmp(rhs, lhs)); 9466ff6d951SJohn Birrell } 9476ff6d951SJohn Birrell 9486ff6d951SJohn Birrell static int 9496ff6d951SJohn Birrell dt_aggregate_valvarrevcmp(const void *lhs, const void *rhs) 9506ff6d951SJohn Birrell { 9516ff6d951SJohn Birrell return (dt_aggregate_valvarcmp(rhs, lhs)); 9526ff6d951SJohn Birrell } 9536ff6d951SJohn Birrell 9546ff6d951SJohn Birrell static int 9556ff6d951SJohn Birrell dt_aggregate_varvalrevcmp(const void *lhs, const void *rhs) 9566ff6d951SJohn Birrell { 9576ff6d951SJohn Birrell return (dt_aggregate_varvalcmp(rhs, lhs)); 9586ff6d951SJohn Birrell } 9596ff6d951SJohn Birrell 9606ff6d951SJohn Birrell static int 9616ff6d951SJohn Birrell dt_aggregate_bundlecmp(const void *lhs, const void *rhs) 9626ff6d951SJohn Birrell { 9636ff6d951SJohn Birrell dt_ahashent_t **lh = *((dt_ahashent_t ***)lhs); 9646ff6d951SJohn Birrell dt_ahashent_t **rh = *((dt_ahashent_t ***)rhs); 9656ff6d951SJohn Birrell int i, rval; 9666ff6d951SJohn Birrell 9676ff6d951SJohn Birrell if (dt_keysort) { 9686ff6d951SJohn Birrell /* 9696ff6d951SJohn Birrell * If we're sorting on keys, we need to scan until we find the 9706ff6d951SJohn Birrell * last entry -- that's the representative key. (The order of 9716ff6d951SJohn Birrell * the bundle is values followed by key to accommodate the 9726ff6d951SJohn Birrell * default behavior of sorting by value.) If the keys are 9736ff6d951SJohn Birrell * equal, we'll fall into the value comparison loop, below. 9746ff6d951SJohn Birrell */ 9756ff6d951SJohn Birrell for (i = 0; lh[i + 1] != NULL; i++) 9766ff6d951SJohn Birrell continue; 9776ff6d951SJohn Birrell 9786ff6d951SJohn Birrell assert(i != 0); 9796ff6d951SJohn Birrell assert(rh[i + 1] == NULL); 9806ff6d951SJohn Birrell 9816ff6d951SJohn Birrell if ((rval = dt_aggregate_keycmp(&lh[i], &rh[i])) != 0) 9826ff6d951SJohn Birrell return (rval); 9836ff6d951SJohn Birrell } 9846ff6d951SJohn Birrell 9856ff6d951SJohn Birrell for (i = 0; ; i++) { 9866ff6d951SJohn Birrell if (lh[i + 1] == NULL) { 9876ff6d951SJohn Birrell /* 9886ff6d951SJohn Birrell * All of the values are equal; if we're sorting on 9896ff6d951SJohn Birrell * keys, then we're only here because the keys were 9906ff6d951SJohn Birrell * found to be equal and these records are therefore 9916ff6d951SJohn Birrell * equal. If we're not sorting on keys, we'll use the 9926ff6d951SJohn Birrell * key comparison from the representative key as the 9936ff6d951SJohn Birrell * tie-breaker. 9946ff6d951SJohn Birrell */ 9956ff6d951SJohn Birrell if (dt_keysort) 9966ff6d951SJohn Birrell return (0); 9976ff6d951SJohn Birrell 9986ff6d951SJohn Birrell assert(i != 0); 9996ff6d951SJohn Birrell assert(rh[i + 1] == NULL); 10006ff6d951SJohn Birrell return (dt_aggregate_keycmp(&lh[i], &rh[i])); 10016ff6d951SJohn Birrell } else { 10026ff6d951SJohn Birrell if ((rval = dt_aggregate_valcmp(&lh[i], &rh[i])) != 0) 10036ff6d951SJohn Birrell return (rval); 10046ff6d951SJohn Birrell } 10056ff6d951SJohn Birrell } 10066ff6d951SJohn Birrell } 10076ff6d951SJohn Birrell 10086ff6d951SJohn Birrell int 10096ff6d951SJohn Birrell dt_aggregate_go(dtrace_hdl_t *dtp) 10106ff6d951SJohn Birrell { 10116ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 10126ff6d951SJohn Birrell dtrace_optval_t size, cpu; 10136ff6d951SJohn Birrell dtrace_bufdesc_t *buf = &agp->dtat_buf; 10146ff6d951SJohn Birrell int rval, i; 10156ff6d951SJohn Birrell 10166ff6d951SJohn Birrell assert(agp->dtat_maxcpu == 0); 10176ff6d951SJohn Birrell assert(agp->dtat_ncpu == 0); 10186ff6d951SJohn Birrell assert(agp->dtat_cpus == NULL); 10196ff6d951SJohn Birrell 10206ff6d951SJohn Birrell agp->dtat_maxcpu = dt_sysconf(dtp, _SC_CPUID_MAX) + 1; 10216ff6d951SJohn Birrell agp->dtat_ncpu = dt_sysconf(dtp, _SC_NPROCESSORS_MAX); 10226ff6d951SJohn Birrell agp->dtat_cpus = malloc(agp->dtat_ncpu * sizeof (processorid_t)); 10236ff6d951SJohn Birrell 10246ff6d951SJohn Birrell if (agp->dtat_cpus == NULL) 10256ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 10266ff6d951SJohn Birrell 10276ff6d951SJohn Birrell /* 10286ff6d951SJohn Birrell * Use the aggregation buffer size as reloaded from the kernel. 10296ff6d951SJohn Birrell */ 10306ff6d951SJohn Birrell size = dtp->dt_options[DTRACEOPT_AGGSIZE]; 10316ff6d951SJohn Birrell 10326ff6d951SJohn Birrell rval = dtrace_getopt(dtp, "aggsize", &size); 10336ff6d951SJohn Birrell assert(rval == 0); 10346ff6d951SJohn Birrell 10356ff6d951SJohn Birrell if (size == 0 || size == DTRACEOPT_UNSET) 10366ff6d951SJohn Birrell return (0); 10376ff6d951SJohn Birrell 10386ff6d951SJohn Birrell buf = &agp->dtat_buf; 10396ff6d951SJohn Birrell buf->dtbd_size = size; 10406ff6d951SJohn Birrell 10416ff6d951SJohn Birrell if ((buf->dtbd_data = malloc(buf->dtbd_size)) == NULL) 10426ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_NOMEM)); 10436ff6d951SJohn Birrell 10446ff6d951SJohn Birrell /* 10456ff6d951SJohn Birrell * Now query for the CPUs enabled. 10466ff6d951SJohn Birrell */ 10476ff6d951SJohn Birrell rval = dtrace_getopt(dtp, "cpu", &cpu); 10486ff6d951SJohn Birrell assert(rval == 0 && cpu != DTRACEOPT_UNSET); 10496ff6d951SJohn Birrell 10506ff6d951SJohn Birrell if (cpu != DTRACE_CPUALL) { 10516ff6d951SJohn Birrell assert(cpu < agp->dtat_ncpu); 10526ff6d951SJohn Birrell agp->dtat_cpus[agp->dtat_ncpus++] = (processorid_t)cpu; 10536ff6d951SJohn Birrell 10546ff6d951SJohn Birrell return (0); 10556ff6d951SJohn Birrell } 10566ff6d951SJohn Birrell 10576ff6d951SJohn Birrell agp->dtat_ncpus = 0; 10586ff6d951SJohn Birrell for (i = 0; i < agp->dtat_maxcpu; i++) { 10596ff6d951SJohn Birrell if (dt_status(dtp, i) == -1) 10606ff6d951SJohn Birrell continue; 10616ff6d951SJohn Birrell 10626ff6d951SJohn Birrell agp->dtat_cpus[agp->dtat_ncpus++] = i; 10636ff6d951SJohn Birrell } 10646ff6d951SJohn Birrell 10656ff6d951SJohn Birrell return (0); 10666ff6d951SJohn Birrell } 10676ff6d951SJohn Birrell 10686ff6d951SJohn Birrell static int 10696ff6d951SJohn Birrell dt_aggwalk_rval(dtrace_hdl_t *dtp, dt_ahashent_t *h, int rval) 10706ff6d951SJohn Birrell { 10716ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 10726ff6d951SJohn Birrell dtrace_aggdata_t *data; 10736ff6d951SJohn Birrell dtrace_aggdesc_t *aggdesc; 10746ff6d951SJohn Birrell dtrace_recdesc_t *rec; 10756ff6d951SJohn Birrell int i; 10766ff6d951SJohn Birrell 10776ff6d951SJohn Birrell switch (rval) { 10786ff6d951SJohn Birrell case DTRACE_AGGWALK_NEXT: 10796ff6d951SJohn Birrell break; 10806ff6d951SJohn Birrell 10816ff6d951SJohn Birrell case DTRACE_AGGWALK_CLEAR: { 10826ff6d951SJohn Birrell uint32_t size, offs = 0; 10836ff6d951SJohn Birrell 10846ff6d951SJohn Birrell aggdesc = h->dtahe_data.dtada_desc; 10856ff6d951SJohn Birrell rec = &aggdesc->dtagd_rec[aggdesc->dtagd_nrecs - 1]; 10866ff6d951SJohn Birrell size = rec->dtrd_size; 10876ff6d951SJohn Birrell data = &h->dtahe_data; 10886ff6d951SJohn Birrell 10896ff6d951SJohn Birrell if (rec->dtrd_action == DTRACEAGG_LQUANTIZE) { 10906ff6d951SJohn Birrell offs = sizeof (uint64_t); 10916ff6d951SJohn Birrell size -= sizeof (uint64_t); 10926ff6d951SJohn Birrell } 10936ff6d951SJohn Birrell 10946ff6d951SJohn Birrell bzero(&data->dtada_data[rec->dtrd_offset] + offs, size); 10956ff6d951SJohn Birrell 10966ff6d951SJohn Birrell if (data->dtada_percpu == NULL) 10976ff6d951SJohn Birrell break; 10986ff6d951SJohn Birrell 10996ff6d951SJohn Birrell for (i = 0; i < dtp->dt_aggregate.dtat_maxcpu; i++) 11006ff6d951SJohn Birrell bzero(data->dtada_percpu[i] + offs, size); 11016ff6d951SJohn Birrell break; 11026ff6d951SJohn Birrell } 11036ff6d951SJohn Birrell 11046ff6d951SJohn Birrell case DTRACE_AGGWALK_ERROR: 11056ff6d951SJohn Birrell /* 11066ff6d951SJohn Birrell * We assume that errno is already set in this case. 11076ff6d951SJohn Birrell */ 11086ff6d951SJohn Birrell return (dt_set_errno(dtp, errno)); 11096ff6d951SJohn Birrell 11106ff6d951SJohn Birrell case DTRACE_AGGWALK_ABORT: 11116ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_DIRABORT)); 11126ff6d951SJohn Birrell 11136ff6d951SJohn Birrell case DTRACE_AGGWALK_DENORMALIZE: 11146ff6d951SJohn Birrell h->dtahe_data.dtada_normal = 1; 11156ff6d951SJohn Birrell return (0); 11166ff6d951SJohn Birrell 11176ff6d951SJohn Birrell case DTRACE_AGGWALK_NORMALIZE: 11186ff6d951SJohn Birrell if (h->dtahe_data.dtada_normal == 0) { 11196ff6d951SJohn Birrell h->dtahe_data.dtada_normal = 1; 11206ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_BADRVAL)); 11216ff6d951SJohn Birrell } 11226ff6d951SJohn Birrell 11236ff6d951SJohn Birrell return (0); 11246ff6d951SJohn Birrell 11256ff6d951SJohn Birrell case DTRACE_AGGWALK_REMOVE: { 11266ff6d951SJohn Birrell dtrace_aggdata_t *aggdata = &h->dtahe_data; 1127d9ce0144SJohn Birrell int max_cpus = agp->dtat_maxcpu; 11286ff6d951SJohn Birrell 11296ff6d951SJohn Birrell /* 11306ff6d951SJohn Birrell * First, remove this hash entry from its hash chain. 11316ff6d951SJohn Birrell */ 11326ff6d951SJohn Birrell if (h->dtahe_prev != NULL) { 11336ff6d951SJohn Birrell h->dtahe_prev->dtahe_next = h->dtahe_next; 11346ff6d951SJohn Birrell } else { 11356ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 11366ff6d951SJohn Birrell size_t ndx = h->dtahe_hashval % hash->dtah_size; 11376ff6d951SJohn Birrell 11386ff6d951SJohn Birrell assert(hash->dtah_hash[ndx] == h); 11396ff6d951SJohn Birrell hash->dtah_hash[ndx] = h->dtahe_next; 11406ff6d951SJohn Birrell } 11416ff6d951SJohn Birrell 11426ff6d951SJohn Birrell if (h->dtahe_next != NULL) 11436ff6d951SJohn Birrell h->dtahe_next->dtahe_prev = h->dtahe_prev; 11446ff6d951SJohn Birrell 11456ff6d951SJohn Birrell /* 11466ff6d951SJohn Birrell * Now remove it from the list of all hash entries. 11476ff6d951SJohn Birrell */ 11486ff6d951SJohn Birrell if (h->dtahe_prevall != NULL) { 11496ff6d951SJohn Birrell h->dtahe_prevall->dtahe_nextall = h->dtahe_nextall; 11506ff6d951SJohn Birrell } else { 11516ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 11526ff6d951SJohn Birrell 11536ff6d951SJohn Birrell assert(hash->dtah_all == h); 11546ff6d951SJohn Birrell hash->dtah_all = h->dtahe_nextall; 11556ff6d951SJohn Birrell } 11566ff6d951SJohn Birrell 11576ff6d951SJohn Birrell if (h->dtahe_nextall != NULL) 11586ff6d951SJohn Birrell h->dtahe_nextall->dtahe_prevall = h->dtahe_prevall; 11596ff6d951SJohn Birrell 11606ff6d951SJohn Birrell /* 11616ff6d951SJohn Birrell * We're unlinked. We can safely destroy the data. 11626ff6d951SJohn Birrell */ 11636ff6d951SJohn Birrell if (aggdata->dtada_percpu != NULL) { 11646ff6d951SJohn Birrell for (i = 0; i < max_cpus; i++) 11656ff6d951SJohn Birrell free(aggdata->dtada_percpu[i]); 11666ff6d951SJohn Birrell free(aggdata->dtada_percpu); 11676ff6d951SJohn Birrell } 11686ff6d951SJohn Birrell 11696ff6d951SJohn Birrell free(aggdata->dtada_data); 11706ff6d951SJohn Birrell free(h); 11716ff6d951SJohn Birrell 11726ff6d951SJohn Birrell return (0); 11736ff6d951SJohn Birrell } 11746ff6d951SJohn Birrell 11756ff6d951SJohn Birrell default: 11766ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_BADRVAL)); 11776ff6d951SJohn Birrell } 11786ff6d951SJohn Birrell 11796ff6d951SJohn Birrell return (0); 11806ff6d951SJohn Birrell } 11816ff6d951SJohn Birrell 11826ff6d951SJohn Birrell void 11836ff6d951SJohn Birrell dt_aggregate_qsort(dtrace_hdl_t *dtp, void *base, size_t nel, size_t width, 11846ff6d951SJohn Birrell int (*compar)(const void *, const void *)) 11856ff6d951SJohn Birrell { 11866ff6d951SJohn Birrell int rev = dt_revsort, key = dt_keysort, keypos = dt_keypos; 11876ff6d951SJohn Birrell dtrace_optval_t keyposopt = dtp->dt_options[DTRACEOPT_AGGSORTKEYPOS]; 11886ff6d951SJohn Birrell 11896ff6d951SJohn Birrell dt_revsort = (dtp->dt_options[DTRACEOPT_AGGSORTREV] != DTRACEOPT_UNSET); 11906ff6d951SJohn Birrell dt_keysort = (dtp->dt_options[DTRACEOPT_AGGSORTKEY] != DTRACEOPT_UNSET); 11916ff6d951SJohn Birrell 11926ff6d951SJohn Birrell if (keyposopt != DTRACEOPT_UNSET && keyposopt <= INT_MAX) { 11936ff6d951SJohn Birrell dt_keypos = (int)keyposopt; 11946ff6d951SJohn Birrell } else { 11956ff6d951SJohn Birrell dt_keypos = 0; 11966ff6d951SJohn Birrell } 11976ff6d951SJohn Birrell 11986ff6d951SJohn Birrell if (compar == NULL) { 11996ff6d951SJohn Birrell if (!dt_keysort) { 12006ff6d951SJohn Birrell compar = dt_aggregate_varvalcmp; 12016ff6d951SJohn Birrell } else { 12026ff6d951SJohn Birrell compar = dt_aggregate_varkeycmp; 12036ff6d951SJohn Birrell } 12046ff6d951SJohn Birrell } 12056ff6d951SJohn Birrell 12066ff6d951SJohn Birrell qsort(base, nel, width, compar); 12076ff6d951SJohn Birrell 12086ff6d951SJohn Birrell dt_revsort = rev; 12096ff6d951SJohn Birrell dt_keysort = key; 12106ff6d951SJohn Birrell dt_keypos = keypos; 12116ff6d951SJohn Birrell } 12126ff6d951SJohn Birrell 12136ff6d951SJohn Birrell int 12146ff6d951SJohn Birrell dtrace_aggregate_walk(dtrace_hdl_t *dtp, dtrace_aggregate_f *func, void *arg) 12156ff6d951SJohn Birrell { 12166ff6d951SJohn Birrell dt_ahashent_t *h, *next; 12176ff6d951SJohn Birrell dt_ahash_t *hash = &dtp->dt_aggregate.dtat_hash; 12186ff6d951SJohn Birrell 12196ff6d951SJohn Birrell for (h = hash->dtah_all; h != NULL; h = next) { 12206ff6d951SJohn Birrell /* 12216ff6d951SJohn Birrell * dt_aggwalk_rval() can potentially remove the current hash 12226ff6d951SJohn Birrell * entry; we need to load the next hash entry before calling 12236ff6d951SJohn Birrell * into it. 12246ff6d951SJohn Birrell */ 12256ff6d951SJohn Birrell next = h->dtahe_nextall; 12266ff6d951SJohn Birrell 12276ff6d951SJohn Birrell if (dt_aggwalk_rval(dtp, h, func(&h->dtahe_data, arg)) == -1) 12286ff6d951SJohn Birrell return (-1); 12296ff6d951SJohn Birrell } 12306ff6d951SJohn Birrell 12316ff6d951SJohn Birrell return (0); 12326ff6d951SJohn Birrell } 12336ff6d951SJohn Birrell 12346ff6d951SJohn Birrell static int 12356ff6d951SJohn Birrell dt_aggregate_walk_sorted(dtrace_hdl_t *dtp, 12366ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg, 12376ff6d951SJohn Birrell int (*sfunc)(const void *, const void *)) 12386ff6d951SJohn Birrell { 12396ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 12406ff6d951SJohn Birrell dt_ahashent_t *h, **sorted; 12416ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 12426ff6d951SJohn Birrell size_t i, nentries = 0; 12436ff6d951SJohn Birrell 12446ff6d951SJohn Birrell for (h = hash->dtah_all; h != NULL; h = h->dtahe_nextall) 12456ff6d951SJohn Birrell nentries++; 12466ff6d951SJohn Birrell 12476ff6d951SJohn Birrell sorted = dt_alloc(dtp, nentries * sizeof (dt_ahashent_t *)); 12486ff6d951SJohn Birrell 12496ff6d951SJohn Birrell if (sorted == NULL) 12506ff6d951SJohn Birrell return (-1); 12516ff6d951SJohn Birrell 12526ff6d951SJohn Birrell for (h = hash->dtah_all, i = 0; h != NULL; h = h->dtahe_nextall) 12536ff6d951SJohn Birrell sorted[i++] = h; 12546ff6d951SJohn Birrell 12556ff6d951SJohn Birrell (void) pthread_mutex_lock(&dt_qsort_lock); 12566ff6d951SJohn Birrell 12576ff6d951SJohn Birrell if (sfunc == NULL) { 12586ff6d951SJohn Birrell dt_aggregate_qsort(dtp, sorted, nentries, 12596ff6d951SJohn Birrell sizeof (dt_ahashent_t *), NULL); 12606ff6d951SJohn Birrell } else { 12616ff6d951SJohn Birrell /* 12626ff6d951SJohn Birrell * If we've been explicitly passed a sorting function, 12636ff6d951SJohn Birrell * we'll use that -- ignoring the values of the "aggsortrev", 12646ff6d951SJohn Birrell * "aggsortkey" and "aggsortkeypos" options. 12656ff6d951SJohn Birrell */ 12666ff6d951SJohn Birrell qsort(sorted, nentries, sizeof (dt_ahashent_t *), sfunc); 12676ff6d951SJohn Birrell } 12686ff6d951SJohn Birrell 12696ff6d951SJohn Birrell (void) pthread_mutex_unlock(&dt_qsort_lock); 12706ff6d951SJohn Birrell 12716ff6d951SJohn Birrell for (i = 0; i < nentries; i++) { 12726ff6d951SJohn Birrell h = sorted[i]; 12736ff6d951SJohn Birrell 12746ff6d951SJohn Birrell if (dt_aggwalk_rval(dtp, h, func(&h->dtahe_data, arg)) == -1) { 12756ff6d951SJohn Birrell dt_free(dtp, sorted); 12766ff6d951SJohn Birrell return (-1); 12776ff6d951SJohn Birrell } 12786ff6d951SJohn Birrell } 12796ff6d951SJohn Birrell 12806ff6d951SJohn Birrell dt_free(dtp, sorted); 12816ff6d951SJohn Birrell return (0); 12826ff6d951SJohn Birrell } 12836ff6d951SJohn Birrell 12846ff6d951SJohn Birrell int 12856ff6d951SJohn Birrell dtrace_aggregate_walk_sorted(dtrace_hdl_t *dtp, 12866ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 12876ff6d951SJohn Birrell { 12886ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, arg, NULL)); 12896ff6d951SJohn Birrell } 12906ff6d951SJohn Birrell 12916ff6d951SJohn Birrell int 12926ff6d951SJohn Birrell dtrace_aggregate_walk_keysorted(dtrace_hdl_t *dtp, 12936ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 12946ff6d951SJohn Birrell { 12956ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 12966ff6d951SJohn Birrell arg, dt_aggregate_varkeycmp)); 12976ff6d951SJohn Birrell } 12986ff6d951SJohn Birrell 12996ff6d951SJohn Birrell int 13006ff6d951SJohn Birrell dtrace_aggregate_walk_valsorted(dtrace_hdl_t *dtp, 13016ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13026ff6d951SJohn Birrell { 13036ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13046ff6d951SJohn Birrell arg, dt_aggregate_varvalcmp)); 13056ff6d951SJohn Birrell } 13066ff6d951SJohn Birrell 13076ff6d951SJohn Birrell int 13086ff6d951SJohn Birrell dtrace_aggregate_walk_keyvarsorted(dtrace_hdl_t *dtp, 13096ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13106ff6d951SJohn Birrell { 13116ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13126ff6d951SJohn Birrell arg, dt_aggregate_keyvarcmp)); 13136ff6d951SJohn Birrell } 13146ff6d951SJohn Birrell 13156ff6d951SJohn Birrell int 13166ff6d951SJohn Birrell dtrace_aggregate_walk_valvarsorted(dtrace_hdl_t *dtp, 13176ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13186ff6d951SJohn Birrell { 13196ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13206ff6d951SJohn Birrell arg, dt_aggregate_valvarcmp)); 13216ff6d951SJohn Birrell } 13226ff6d951SJohn Birrell 13236ff6d951SJohn Birrell int 13246ff6d951SJohn Birrell dtrace_aggregate_walk_keyrevsorted(dtrace_hdl_t *dtp, 13256ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13266ff6d951SJohn Birrell { 13276ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13286ff6d951SJohn Birrell arg, dt_aggregate_varkeyrevcmp)); 13296ff6d951SJohn Birrell } 13306ff6d951SJohn Birrell 13316ff6d951SJohn Birrell int 13326ff6d951SJohn Birrell dtrace_aggregate_walk_valrevsorted(dtrace_hdl_t *dtp, 13336ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13346ff6d951SJohn Birrell { 13356ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13366ff6d951SJohn Birrell arg, dt_aggregate_varvalrevcmp)); 13376ff6d951SJohn Birrell } 13386ff6d951SJohn Birrell 13396ff6d951SJohn Birrell int 13406ff6d951SJohn Birrell dtrace_aggregate_walk_keyvarrevsorted(dtrace_hdl_t *dtp, 13416ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13426ff6d951SJohn Birrell { 13436ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13446ff6d951SJohn Birrell arg, dt_aggregate_keyvarrevcmp)); 13456ff6d951SJohn Birrell } 13466ff6d951SJohn Birrell 13476ff6d951SJohn Birrell int 13486ff6d951SJohn Birrell dtrace_aggregate_walk_valvarrevsorted(dtrace_hdl_t *dtp, 13496ff6d951SJohn Birrell dtrace_aggregate_f *func, void *arg) 13506ff6d951SJohn Birrell { 13516ff6d951SJohn Birrell return (dt_aggregate_walk_sorted(dtp, func, 13526ff6d951SJohn Birrell arg, dt_aggregate_valvarrevcmp)); 13536ff6d951SJohn Birrell } 13546ff6d951SJohn Birrell 13556ff6d951SJohn Birrell int 13566ff6d951SJohn Birrell dtrace_aggregate_walk_joined(dtrace_hdl_t *dtp, dtrace_aggvarid_t *aggvars, 13576ff6d951SJohn Birrell int naggvars, dtrace_aggregate_walk_joined_f *func, void *arg) 13586ff6d951SJohn Birrell { 13596ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 13606ff6d951SJohn Birrell dt_ahashent_t *h, **sorted = NULL, ***bundle, **nbundle; 13616ff6d951SJohn Birrell const dtrace_aggdata_t **data; 13626ff6d951SJohn Birrell dt_ahashent_t *zaggdata = NULL; 13636ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 13646ff6d951SJohn Birrell size_t nentries = 0, nbundles = 0, start, zsize = 0, bundlesize; 13656ff6d951SJohn Birrell dtrace_aggvarid_t max = 0, aggvar; 13666ff6d951SJohn Birrell int rval = -1, *map, *remap = NULL; 13676ff6d951SJohn Birrell int i, j; 13686ff6d951SJohn Birrell dtrace_optval_t sortpos = dtp->dt_options[DTRACEOPT_AGGSORTPOS]; 13696ff6d951SJohn Birrell 13706ff6d951SJohn Birrell /* 13716ff6d951SJohn Birrell * If the sorting position is greater than the number of aggregation 13726ff6d951SJohn Birrell * variable IDs, we silently set it to 0. 13736ff6d951SJohn Birrell */ 13746ff6d951SJohn Birrell if (sortpos == DTRACEOPT_UNSET || sortpos >= naggvars) 13756ff6d951SJohn Birrell sortpos = 0; 13766ff6d951SJohn Birrell 13776ff6d951SJohn Birrell /* 13786ff6d951SJohn Birrell * First we need to translate the specified aggregation variable IDs 13796ff6d951SJohn Birrell * into a linear map that will allow us to translate an aggregation 13806ff6d951SJohn Birrell * variable ID into its position in the specified aggvars. 13816ff6d951SJohn Birrell */ 13826ff6d951SJohn Birrell for (i = 0; i < naggvars; i++) { 13836ff6d951SJohn Birrell if (aggvars[i] == DTRACE_AGGVARIDNONE || aggvars[i] < 0) 13846ff6d951SJohn Birrell return (dt_set_errno(dtp, EDT_BADAGGVAR)); 13856ff6d951SJohn Birrell 13866ff6d951SJohn Birrell if (aggvars[i] > max) 13876ff6d951SJohn Birrell max = aggvars[i]; 13886ff6d951SJohn Birrell } 13896ff6d951SJohn Birrell 13906ff6d951SJohn Birrell if ((map = dt_zalloc(dtp, (max + 1) * sizeof (int))) == NULL) 13916ff6d951SJohn Birrell return (-1); 13926ff6d951SJohn Birrell 13936ff6d951SJohn Birrell zaggdata = dt_zalloc(dtp, naggvars * sizeof (dt_ahashent_t)); 13946ff6d951SJohn Birrell 13956ff6d951SJohn Birrell if (zaggdata == NULL) 13966ff6d951SJohn Birrell goto out; 13976ff6d951SJohn Birrell 13986ff6d951SJohn Birrell for (i = 0; i < naggvars; i++) { 13996ff6d951SJohn Birrell int ndx = i + sortpos; 14006ff6d951SJohn Birrell 14016ff6d951SJohn Birrell if (ndx >= naggvars) 14026ff6d951SJohn Birrell ndx -= naggvars; 14036ff6d951SJohn Birrell 14046ff6d951SJohn Birrell aggvar = aggvars[ndx]; 14056ff6d951SJohn Birrell assert(aggvar <= max); 14066ff6d951SJohn Birrell 14076ff6d951SJohn Birrell if (map[aggvar]) { 14086ff6d951SJohn Birrell /* 14096ff6d951SJohn Birrell * We have an aggregation variable that is present 14106ff6d951SJohn Birrell * more than once in the array of aggregation 14116ff6d951SJohn Birrell * variables. While it's unclear why one might want 14126ff6d951SJohn Birrell * to do this, it's legal. To support this construct, 14136ff6d951SJohn Birrell * we will allocate a remap that will indicate the 14146ff6d951SJohn Birrell * position from which this aggregation variable 14156ff6d951SJohn Birrell * should be pulled. (That is, where the remap will 14166ff6d951SJohn Birrell * map from one position to another.) 14176ff6d951SJohn Birrell */ 14186ff6d951SJohn Birrell if (remap == NULL) { 14196ff6d951SJohn Birrell remap = dt_zalloc(dtp, naggvars * sizeof (int)); 14206ff6d951SJohn Birrell 14216ff6d951SJohn Birrell if (remap == NULL) 14226ff6d951SJohn Birrell goto out; 14236ff6d951SJohn Birrell } 14246ff6d951SJohn Birrell 14256ff6d951SJohn Birrell /* 14266ff6d951SJohn Birrell * Given that the variable is already present, assert 14276ff6d951SJohn Birrell * that following through the mapping and adjusting 14286ff6d951SJohn Birrell * for the sort position yields the same aggregation 14296ff6d951SJohn Birrell * variable ID. 14306ff6d951SJohn Birrell */ 14316ff6d951SJohn Birrell assert(aggvars[(map[aggvar] - 1 + sortpos) % 14326ff6d951SJohn Birrell naggvars] == aggvars[ndx]); 14336ff6d951SJohn Birrell 14346ff6d951SJohn Birrell remap[i] = map[aggvar]; 14356ff6d951SJohn Birrell continue; 14366ff6d951SJohn Birrell } 14376ff6d951SJohn Birrell 14386ff6d951SJohn Birrell map[aggvar] = i + 1; 14396ff6d951SJohn Birrell } 14406ff6d951SJohn Birrell 14416ff6d951SJohn Birrell /* 14426ff6d951SJohn Birrell * We need to take two passes over the data to size our allocation, so 14436ff6d951SJohn Birrell * we'll use the first pass to also fill in the zero-filled data to be 14446ff6d951SJohn Birrell * used to properly format a zero-valued aggregation. 14456ff6d951SJohn Birrell */ 14466ff6d951SJohn Birrell for (h = hash->dtah_all; h != NULL; h = h->dtahe_nextall) { 14476ff6d951SJohn Birrell dtrace_aggvarid_t id; 14486ff6d951SJohn Birrell int ndx; 14496ff6d951SJohn Birrell 14506ff6d951SJohn Birrell if ((id = dt_aggregate_aggvarid(h)) > max || !(ndx = map[id])) 14516ff6d951SJohn Birrell continue; 14526ff6d951SJohn Birrell 14536ff6d951SJohn Birrell if (zaggdata[ndx - 1].dtahe_size == 0) { 14546ff6d951SJohn Birrell zaggdata[ndx - 1].dtahe_size = h->dtahe_size; 14556ff6d951SJohn Birrell zaggdata[ndx - 1].dtahe_data = h->dtahe_data; 14566ff6d951SJohn Birrell } 14576ff6d951SJohn Birrell 14586ff6d951SJohn Birrell nentries++; 14596ff6d951SJohn Birrell } 14606ff6d951SJohn Birrell 14616ff6d951SJohn Birrell if (nentries == 0) { 14626ff6d951SJohn Birrell /* 14636ff6d951SJohn Birrell * We couldn't find any entries; there is nothing else to do. 14646ff6d951SJohn Birrell */ 14656ff6d951SJohn Birrell rval = 0; 14666ff6d951SJohn Birrell goto out; 14676ff6d951SJohn Birrell } 14686ff6d951SJohn Birrell 14696ff6d951SJohn Birrell /* 14706ff6d951SJohn Birrell * Before we sort the data, we're going to look for any holes in our 14716ff6d951SJohn Birrell * zero-filled data. This will occur if an aggregation variable that 14726ff6d951SJohn Birrell * we are being asked to print has not yet been assigned the result of 14736ff6d951SJohn Birrell * any aggregating action for _any_ tuple. The issue becomes that we 14746ff6d951SJohn Birrell * would like a zero value to be printed for all columns for this 14756ff6d951SJohn Birrell * aggregation, but without any record description, we don't know the 14766ff6d951SJohn Birrell * aggregating action that corresponds to the aggregation variable. To 14776ff6d951SJohn Birrell * try to find a match, we're simply going to lookup aggregation IDs 14786ff6d951SJohn Birrell * (which are guaranteed to be contiguous and to start from 1), looking 14796ff6d951SJohn Birrell * for the specified aggregation variable ID. If we find a match, 14806ff6d951SJohn Birrell * we'll use that. If we iterate over all aggregation IDs and don't 14816ff6d951SJohn Birrell * find a match, then we must be an anonymous enabling. (Anonymous 14826ff6d951SJohn Birrell * enablings can't currently derive either aggregation variable IDs or 14836ff6d951SJohn Birrell * aggregation variable names given only an aggregation ID.) In this 14846ff6d951SJohn Birrell * obscure case (anonymous enabling, multiple aggregation printa() with 14856ff6d951SJohn Birrell * some aggregations not represented for any tuple), our defined 14866ff6d951SJohn Birrell * behavior is that the zero will be printed in the format of the first 14876ff6d951SJohn Birrell * aggregation variable that contains any non-zero value. 14886ff6d951SJohn Birrell */ 14896ff6d951SJohn Birrell for (i = 0; i < naggvars; i++) { 14906ff6d951SJohn Birrell if (zaggdata[i].dtahe_size == 0) { 14916ff6d951SJohn Birrell dtrace_aggvarid_t aggvar; 14926ff6d951SJohn Birrell 14936ff6d951SJohn Birrell aggvar = aggvars[(i - sortpos + naggvars) % naggvars]; 14946ff6d951SJohn Birrell assert(zaggdata[i].dtahe_data.dtada_data == NULL); 14956ff6d951SJohn Birrell 14966ff6d951SJohn Birrell for (j = DTRACE_AGGIDNONE + 1; ; j++) { 14976ff6d951SJohn Birrell dtrace_aggdesc_t *agg; 14986ff6d951SJohn Birrell dtrace_aggdata_t *aggdata; 14996ff6d951SJohn Birrell 15006ff6d951SJohn Birrell if (dt_aggid_lookup(dtp, j, &agg) != 0) 15016ff6d951SJohn Birrell break; 15026ff6d951SJohn Birrell 15036ff6d951SJohn Birrell if (agg->dtagd_varid != aggvar) 15046ff6d951SJohn Birrell continue; 15056ff6d951SJohn Birrell 15066ff6d951SJohn Birrell /* 15076ff6d951SJohn Birrell * We have our description -- now we need to 15086ff6d951SJohn Birrell * cons up the zaggdata entry for it. 15096ff6d951SJohn Birrell */ 15106ff6d951SJohn Birrell aggdata = &zaggdata[i].dtahe_data; 15116ff6d951SJohn Birrell aggdata->dtada_size = agg->dtagd_size; 15126ff6d951SJohn Birrell aggdata->dtada_desc = agg; 15136ff6d951SJohn Birrell aggdata->dtada_handle = dtp; 15146ff6d951SJohn Birrell (void) dt_epid_lookup(dtp, agg->dtagd_epid, 15156ff6d951SJohn Birrell &aggdata->dtada_edesc, 15166ff6d951SJohn Birrell &aggdata->dtada_pdesc); 15176ff6d951SJohn Birrell aggdata->dtada_normal = 1; 15186ff6d951SJohn Birrell zaggdata[i].dtahe_hashval = 0; 15196ff6d951SJohn Birrell zaggdata[i].dtahe_size = agg->dtagd_size; 15206ff6d951SJohn Birrell break; 15216ff6d951SJohn Birrell } 15226ff6d951SJohn Birrell 15236ff6d951SJohn Birrell if (zaggdata[i].dtahe_size == 0) { 15246ff6d951SJohn Birrell caddr_t data; 15256ff6d951SJohn Birrell 15266ff6d951SJohn Birrell /* 15276ff6d951SJohn Birrell * We couldn't find this aggregation, meaning 15286ff6d951SJohn Birrell * that we have never seen it before for any 15296ff6d951SJohn Birrell * tuple _and_ this is an anonymous enabling. 15306ff6d951SJohn Birrell * That is, we're in the obscure case outlined 15316ff6d951SJohn Birrell * above. In this case, our defined behavior 15326ff6d951SJohn Birrell * is to format the data in the format of the 15336ff6d951SJohn Birrell * first non-zero aggregation -- of which, of 15346ff6d951SJohn Birrell * course, we know there to be at least one 15356ff6d951SJohn Birrell * (or nentries would have been zero). 15366ff6d951SJohn Birrell */ 15376ff6d951SJohn Birrell for (j = 0; j < naggvars; j++) { 15386ff6d951SJohn Birrell if (zaggdata[j].dtahe_size != 0) 15396ff6d951SJohn Birrell break; 15406ff6d951SJohn Birrell } 15416ff6d951SJohn Birrell 15426ff6d951SJohn Birrell assert(j < naggvars); 15436ff6d951SJohn Birrell zaggdata[i] = zaggdata[j]; 15446ff6d951SJohn Birrell 15456ff6d951SJohn Birrell data = zaggdata[i].dtahe_data.dtada_data; 15466ff6d951SJohn Birrell assert(data != NULL); 15476ff6d951SJohn Birrell } 15486ff6d951SJohn Birrell } 15496ff6d951SJohn Birrell } 15506ff6d951SJohn Birrell 15516ff6d951SJohn Birrell /* 15526ff6d951SJohn Birrell * Now we need to allocate our zero-filled data for use for 15536ff6d951SJohn Birrell * aggregations that don't have a value corresponding to a given key. 15546ff6d951SJohn Birrell */ 15556ff6d951SJohn Birrell for (i = 0; i < naggvars; i++) { 15566ff6d951SJohn Birrell dtrace_aggdata_t *aggdata = &zaggdata[i].dtahe_data; 15576ff6d951SJohn Birrell dtrace_aggdesc_t *aggdesc = aggdata->dtada_desc; 15586ff6d951SJohn Birrell dtrace_recdesc_t *rec; 15596ff6d951SJohn Birrell uint64_t larg; 15606ff6d951SJohn Birrell caddr_t zdata; 15616ff6d951SJohn Birrell 15626ff6d951SJohn Birrell zsize = zaggdata[i].dtahe_size; 15636ff6d951SJohn Birrell assert(zsize != 0); 15646ff6d951SJohn Birrell 15656ff6d951SJohn Birrell if ((zdata = dt_zalloc(dtp, zsize)) == NULL) { 15666ff6d951SJohn Birrell /* 15676ff6d951SJohn Birrell * If we failed to allocated some zero-filled data, we 15686ff6d951SJohn Birrell * need to zero out the remaining dtada_data pointers 15696ff6d951SJohn Birrell * to prevent the wrong data from being freed below. 15706ff6d951SJohn Birrell */ 15716ff6d951SJohn Birrell for (j = i; j < naggvars; j++) 15726ff6d951SJohn Birrell zaggdata[j].dtahe_data.dtada_data = NULL; 15736ff6d951SJohn Birrell goto out; 15746ff6d951SJohn Birrell } 15756ff6d951SJohn Birrell 15766ff6d951SJohn Birrell aggvar = aggvars[(i - sortpos + naggvars) % naggvars]; 15776ff6d951SJohn Birrell 15786ff6d951SJohn Birrell /* 15796ff6d951SJohn Birrell * First, the easy bit. To maintain compatibility with 15806ff6d951SJohn Birrell * consumers that pull the compiler-generated ID out of the 15816ff6d951SJohn Birrell * data, we put that ID at the top of the zero-filled data. 15826ff6d951SJohn Birrell */ 15836ff6d951SJohn Birrell rec = &aggdesc->dtagd_rec[0]; 15846ff6d951SJohn Birrell /* LINTED - alignment */ 15856ff6d951SJohn Birrell *((dtrace_aggvarid_t *)(zdata + rec->dtrd_offset)) = aggvar; 15866ff6d951SJohn Birrell 15876ff6d951SJohn Birrell rec = &aggdesc->dtagd_rec[aggdesc->dtagd_nrecs - 1]; 15886ff6d951SJohn Birrell 15896ff6d951SJohn Birrell /* 15906ff6d951SJohn Birrell * Now for the more complicated part. If (and only if) this 15916ff6d951SJohn Birrell * is an lquantize() aggregating action, zero-filled data is 15926ff6d951SJohn Birrell * not equivalent to an empty record: we must also get the 15936ff6d951SJohn Birrell * parameters for the lquantize(). 15946ff6d951SJohn Birrell */ 15956ff6d951SJohn Birrell if (rec->dtrd_action == DTRACEAGG_LQUANTIZE) { 15966ff6d951SJohn Birrell if (aggdata->dtada_data != NULL) { 15976ff6d951SJohn Birrell /* 15986ff6d951SJohn Birrell * The easier case here is if we actually have 15996ff6d951SJohn Birrell * some prototype data -- in which case we 16006ff6d951SJohn Birrell * manually dig it out of the aggregation 16016ff6d951SJohn Birrell * record. 16026ff6d951SJohn Birrell */ 16036ff6d951SJohn Birrell /* LINTED - alignment */ 16046ff6d951SJohn Birrell larg = *((uint64_t *)(aggdata->dtada_data + 16056ff6d951SJohn Birrell rec->dtrd_offset)); 16066ff6d951SJohn Birrell } else { 16076ff6d951SJohn Birrell /* 16086ff6d951SJohn Birrell * We don't have any prototype data. As a 16096ff6d951SJohn Birrell * result, we know that we _do_ have the 16106ff6d951SJohn Birrell * compiler-generated information. (If this 16116ff6d951SJohn Birrell * were an anonymous enabling, all of our 16126ff6d951SJohn Birrell * zero-filled data would have prototype data 16136ff6d951SJohn Birrell * -- either directly or indirectly.) So as 16146ff6d951SJohn Birrell * gross as it is, we'll grovel around in the 16156ff6d951SJohn Birrell * compiler-generated information to find the 16166ff6d951SJohn Birrell * lquantize() parameters. 16176ff6d951SJohn Birrell */ 16186ff6d951SJohn Birrell dtrace_stmtdesc_t *sdp; 16196ff6d951SJohn Birrell dt_ident_t *aid; 16206ff6d951SJohn Birrell dt_idsig_t *isp; 16216ff6d951SJohn Birrell 16226ff6d951SJohn Birrell sdp = (dtrace_stmtdesc_t *)(uintptr_t) 16236ff6d951SJohn Birrell aggdesc->dtagd_rec[0].dtrd_uarg; 16246ff6d951SJohn Birrell aid = sdp->dtsd_aggdata; 16256ff6d951SJohn Birrell isp = (dt_idsig_t *)aid->di_data; 16266ff6d951SJohn Birrell assert(isp->dis_auxinfo != 0); 16276ff6d951SJohn Birrell larg = isp->dis_auxinfo; 16286ff6d951SJohn Birrell } 16296ff6d951SJohn Birrell 16306ff6d951SJohn Birrell /* LINTED - alignment */ 16316ff6d951SJohn Birrell *((uint64_t *)(zdata + rec->dtrd_offset)) = larg; 16326ff6d951SJohn Birrell } 16336ff6d951SJohn Birrell 16346ff6d951SJohn Birrell aggdata->dtada_data = zdata; 16356ff6d951SJohn Birrell } 16366ff6d951SJohn Birrell 16376ff6d951SJohn Birrell /* 16386ff6d951SJohn Birrell * Now that we've dealt with setting up our zero-filled data, we can 16396ff6d951SJohn Birrell * allocate our sorted array, and take another pass over the data to 16406ff6d951SJohn Birrell * fill it. 16416ff6d951SJohn Birrell */ 16426ff6d951SJohn Birrell sorted = dt_alloc(dtp, nentries * sizeof (dt_ahashent_t *)); 16436ff6d951SJohn Birrell 16446ff6d951SJohn Birrell if (sorted == NULL) 16456ff6d951SJohn Birrell goto out; 16466ff6d951SJohn Birrell 16476ff6d951SJohn Birrell for (h = hash->dtah_all, i = 0; h != NULL; h = h->dtahe_nextall) { 16486ff6d951SJohn Birrell dtrace_aggvarid_t id; 16496ff6d951SJohn Birrell 16506ff6d951SJohn Birrell if ((id = dt_aggregate_aggvarid(h)) > max || !map[id]) 16516ff6d951SJohn Birrell continue; 16526ff6d951SJohn Birrell 16536ff6d951SJohn Birrell sorted[i++] = h; 16546ff6d951SJohn Birrell } 16556ff6d951SJohn Birrell 16566ff6d951SJohn Birrell assert(i == nentries); 16576ff6d951SJohn Birrell 16586ff6d951SJohn Birrell /* 16596ff6d951SJohn Birrell * We've loaded our array; now we need to sort by value to allow us 16606ff6d951SJohn Birrell * to create bundles of like value. We're going to acquire the 16616ff6d951SJohn Birrell * dt_qsort_lock here, and hold it across all of our subsequent 16626ff6d951SJohn Birrell * comparison and sorting. 16636ff6d951SJohn Birrell */ 16646ff6d951SJohn Birrell (void) pthread_mutex_lock(&dt_qsort_lock); 16656ff6d951SJohn Birrell 16666ff6d951SJohn Birrell qsort(sorted, nentries, sizeof (dt_ahashent_t *), 16676ff6d951SJohn Birrell dt_aggregate_keyvarcmp); 16686ff6d951SJohn Birrell 16696ff6d951SJohn Birrell /* 16706ff6d951SJohn Birrell * Now we need to go through and create bundles. Because the number 16716ff6d951SJohn Birrell * of bundles is bounded by the size of the sorted array, we're going 16726ff6d951SJohn Birrell * to reuse the underlying storage. And note that "bundle" is an 16736ff6d951SJohn Birrell * array of pointers to arrays of pointers to dt_ahashent_t -- making 16746ff6d951SJohn Birrell * its type (regrettably) "dt_ahashent_t ***". (Regrettable because 16756ff6d951SJohn Birrell * '*' -- like '_' and 'X' -- should never appear in triplicate in 16766ff6d951SJohn Birrell * an ideal world.) 16776ff6d951SJohn Birrell */ 16786ff6d951SJohn Birrell bundle = (dt_ahashent_t ***)sorted; 16796ff6d951SJohn Birrell 16806ff6d951SJohn Birrell for (i = 1, start = 0; i <= nentries; i++) { 16816ff6d951SJohn Birrell if (i < nentries && 16826ff6d951SJohn Birrell dt_aggregate_keycmp(&sorted[i], &sorted[i - 1]) == 0) 16836ff6d951SJohn Birrell continue; 16846ff6d951SJohn Birrell 16856ff6d951SJohn Birrell /* 16866ff6d951SJohn Birrell * We have a bundle boundary. Everything from start to 16876ff6d951SJohn Birrell * (i - 1) belongs in one bundle. 16886ff6d951SJohn Birrell */ 16896ff6d951SJohn Birrell assert(i - start <= naggvars); 16906ff6d951SJohn Birrell bundlesize = (naggvars + 2) * sizeof (dt_ahashent_t *); 16916ff6d951SJohn Birrell 16926ff6d951SJohn Birrell if ((nbundle = dt_zalloc(dtp, bundlesize)) == NULL) { 16936ff6d951SJohn Birrell (void) pthread_mutex_unlock(&dt_qsort_lock); 16946ff6d951SJohn Birrell goto out; 16956ff6d951SJohn Birrell } 16966ff6d951SJohn Birrell 16976ff6d951SJohn Birrell for (j = start; j < i; j++) { 16986ff6d951SJohn Birrell dtrace_aggvarid_t id = dt_aggregate_aggvarid(sorted[j]); 16996ff6d951SJohn Birrell 17006ff6d951SJohn Birrell assert(id <= max); 17016ff6d951SJohn Birrell assert(map[id] != 0); 17026ff6d951SJohn Birrell assert(map[id] - 1 < naggvars); 17036ff6d951SJohn Birrell assert(nbundle[map[id] - 1] == NULL); 17046ff6d951SJohn Birrell nbundle[map[id] - 1] = sorted[j]; 17056ff6d951SJohn Birrell 17066ff6d951SJohn Birrell if (nbundle[naggvars] == NULL) 17076ff6d951SJohn Birrell nbundle[naggvars] = sorted[j]; 17086ff6d951SJohn Birrell } 17096ff6d951SJohn Birrell 17106ff6d951SJohn Birrell for (j = 0; j < naggvars; j++) { 17116ff6d951SJohn Birrell if (nbundle[j] != NULL) 17126ff6d951SJohn Birrell continue; 17136ff6d951SJohn Birrell 17146ff6d951SJohn Birrell /* 17156ff6d951SJohn Birrell * Before we assume that this aggregation variable 17166ff6d951SJohn Birrell * isn't present (and fall back to using the 17176ff6d951SJohn Birrell * zero-filled data allocated earlier), check the 17186ff6d951SJohn Birrell * remap. If we have a remapping, we'll drop it in 17196ff6d951SJohn Birrell * here. Note that we might be remapping an 17206ff6d951SJohn Birrell * aggregation variable that isn't present for this 17216ff6d951SJohn Birrell * key; in this case, the aggregation data that we 17226ff6d951SJohn Birrell * copy will point to the zeroed data. 17236ff6d951SJohn Birrell */ 17246ff6d951SJohn Birrell if (remap != NULL && remap[j]) { 17256ff6d951SJohn Birrell assert(remap[j] - 1 < j); 17266ff6d951SJohn Birrell assert(nbundle[remap[j] - 1] != NULL); 17276ff6d951SJohn Birrell nbundle[j] = nbundle[remap[j] - 1]; 17286ff6d951SJohn Birrell } else { 17296ff6d951SJohn Birrell nbundle[j] = &zaggdata[j]; 17306ff6d951SJohn Birrell } 17316ff6d951SJohn Birrell } 17326ff6d951SJohn Birrell 17336ff6d951SJohn Birrell bundle[nbundles++] = nbundle; 17346ff6d951SJohn Birrell start = i; 17356ff6d951SJohn Birrell } 17366ff6d951SJohn Birrell 17376ff6d951SJohn Birrell /* 17386ff6d951SJohn Birrell * Now we need to re-sort based on the first value. 17396ff6d951SJohn Birrell */ 17406ff6d951SJohn Birrell dt_aggregate_qsort(dtp, bundle, nbundles, sizeof (dt_ahashent_t **), 17416ff6d951SJohn Birrell dt_aggregate_bundlecmp); 17426ff6d951SJohn Birrell 17436ff6d951SJohn Birrell (void) pthread_mutex_unlock(&dt_qsort_lock); 17446ff6d951SJohn Birrell 17456ff6d951SJohn Birrell /* 17466ff6d951SJohn Birrell * We're done! Now we just need to go back over the sorted bundles, 17476ff6d951SJohn Birrell * calling the function. 17486ff6d951SJohn Birrell */ 17496ff6d951SJohn Birrell data = alloca((naggvars + 1) * sizeof (dtrace_aggdata_t *)); 17506ff6d951SJohn Birrell 17516ff6d951SJohn Birrell for (i = 0; i < nbundles; i++) { 17526ff6d951SJohn Birrell for (j = 0; j < naggvars; j++) 17536ff6d951SJohn Birrell data[j + 1] = NULL; 17546ff6d951SJohn Birrell 17556ff6d951SJohn Birrell for (j = 0; j < naggvars; j++) { 17566ff6d951SJohn Birrell int ndx = j - sortpos; 17576ff6d951SJohn Birrell 17586ff6d951SJohn Birrell if (ndx < 0) 17596ff6d951SJohn Birrell ndx += naggvars; 17606ff6d951SJohn Birrell 17616ff6d951SJohn Birrell assert(bundle[i][ndx] != NULL); 17626ff6d951SJohn Birrell data[j + 1] = &bundle[i][ndx]->dtahe_data; 17636ff6d951SJohn Birrell } 17646ff6d951SJohn Birrell 17656ff6d951SJohn Birrell for (j = 0; j < naggvars; j++) 17666ff6d951SJohn Birrell assert(data[j + 1] != NULL); 17676ff6d951SJohn Birrell 17686ff6d951SJohn Birrell /* 17696ff6d951SJohn Birrell * The representative key is the last element in the bundle. 17706ff6d951SJohn Birrell * Assert that we have one, and then set it to be the first 17716ff6d951SJohn Birrell * element of data. 17726ff6d951SJohn Birrell */ 17736ff6d951SJohn Birrell assert(bundle[i][j] != NULL); 17746ff6d951SJohn Birrell data[0] = &bundle[i][j]->dtahe_data; 17756ff6d951SJohn Birrell 17766ff6d951SJohn Birrell if ((rval = func(data, naggvars + 1, arg)) == -1) 17776ff6d951SJohn Birrell goto out; 17786ff6d951SJohn Birrell } 17796ff6d951SJohn Birrell 17806ff6d951SJohn Birrell rval = 0; 17816ff6d951SJohn Birrell out: 17826ff6d951SJohn Birrell for (i = 0; i < nbundles; i++) 17836ff6d951SJohn Birrell dt_free(dtp, bundle[i]); 17846ff6d951SJohn Birrell 17856ff6d951SJohn Birrell if (zaggdata != NULL) { 17866ff6d951SJohn Birrell for (i = 0; i < naggvars; i++) 17876ff6d951SJohn Birrell dt_free(dtp, zaggdata[i].dtahe_data.dtada_data); 17886ff6d951SJohn Birrell } 17896ff6d951SJohn Birrell 17906ff6d951SJohn Birrell dt_free(dtp, zaggdata); 17916ff6d951SJohn Birrell dt_free(dtp, sorted); 17926ff6d951SJohn Birrell dt_free(dtp, remap); 17936ff6d951SJohn Birrell dt_free(dtp, map); 17946ff6d951SJohn Birrell 17956ff6d951SJohn Birrell return (rval); 17966ff6d951SJohn Birrell } 17976ff6d951SJohn Birrell 17986ff6d951SJohn Birrell int 17996ff6d951SJohn Birrell dtrace_aggregate_print(dtrace_hdl_t *dtp, FILE *fp, 18006ff6d951SJohn Birrell dtrace_aggregate_walk_f *func) 18016ff6d951SJohn Birrell { 18026ff6d951SJohn Birrell dt_print_aggdata_t pd; 18036ff6d951SJohn Birrell 18046ff6d951SJohn Birrell pd.dtpa_dtp = dtp; 18056ff6d951SJohn Birrell pd.dtpa_fp = fp; 18066ff6d951SJohn Birrell pd.dtpa_allunprint = 1; 18076ff6d951SJohn Birrell 18086ff6d951SJohn Birrell if (func == NULL) 18096ff6d951SJohn Birrell func = dtrace_aggregate_walk_sorted; 18106ff6d951SJohn Birrell 18116ff6d951SJohn Birrell if ((*func)(dtp, dt_print_agg, &pd) == -1) 18126ff6d951SJohn Birrell return (dt_set_errno(dtp, dtp->dt_errno)); 18136ff6d951SJohn Birrell 18146ff6d951SJohn Birrell return (0); 18156ff6d951SJohn Birrell } 18166ff6d951SJohn Birrell 18176ff6d951SJohn Birrell void 18186ff6d951SJohn Birrell dtrace_aggregate_clear(dtrace_hdl_t *dtp) 18196ff6d951SJohn Birrell { 18206ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 18216ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 18226ff6d951SJohn Birrell dt_ahashent_t *h; 18236ff6d951SJohn Birrell dtrace_aggdata_t *data; 18246ff6d951SJohn Birrell dtrace_aggdesc_t *aggdesc; 18256ff6d951SJohn Birrell dtrace_recdesc_t *rec; 18266ff6d951SJohn Birrell int i, max_cpus = agp->dtat_maxcpu; 18276ff6d951SJohn Birrell 18286ff6d951SJohn Birrell for (h = hash->dtah_all; h != NULL; h = h->dtahe_nextall) { 18296ff6d951SJohn Birrell aggdesc = h->dtahe_data.dtada_desc; 18306ff6d951SJohn Birrell rec = &aggdesc->dtagd_rec[aggdesc->dtagd_nrecs - 1]; 18316ff6d951SJohn Birrell data = &h->dtahe_data; 18326ff6d951SJohn Birrell 18336ff6d951SJohn Birrell bzero(&data->dtada_data[rec->dtrd_offset], rec->dtrd_size); 18346ff6d951SJohn Birrell 18356ff6d951SJohn Birrell if (data->dtada_percpu == NULL) 18366ff6d951SJohn Birrell continue; 18376ff6d951SJohn Birrell 18386ff6d951SJohn Birrell for (i = 0; i < max_cpus; i++) 18396ff6d951SJohn Birrell bzero(data->dtada_percpu[i], rec->dtrd_size); 18406ff6d951SJohn Birrell } 18416ff6d951SJohn Birrell } 18426ff6d951SJohn Birrell 18436ff6d951SJohn Birrell void 18446ff6d951SJohn Birrell dt_aggregate_destroy(dtrace_hdl_t *dtp) 18456ff6d951SJohn Birrell { 18466ff6d951SJohn Birrell dt_aggregate_t *agp = &dtp->dt_aggregate; 18476ff6d951SJohn Birrell dt_ahash_t *hash = &agp->dtat_hash; 18486ff6d951SJohn Birrell dt_ahashent_t *h, *next; 18496ff6d951SJohn Birrell dtrace_aggdata_t *aggdata; 18506ff6d951SJohn Birrell int i, max_cpus = agp->dtat_maxcpu; 18516ff6d951SJohn Birrell 18526ff6d951SJohn Birrell if (hash->dtah_hash == NULL) { 18536ff6d951SJohn Birrell assert(hash->dtah_all == NULL); 18546ff6d951SJohn Birrell } else { 18556ff6d951SJohn Birrell free(hash->dtah_hash); 18566ff6d951SJohn Birrell 18576ff6d951SJohn Birrell for (h = hash->dtah_all; h != NULL; h = next) { 18586ff6d951SJohn Birrell next = h->dtahe_nextall; 18596ff6d951SJohn Birrell 18606ff6d951SJohn Birrell aggdata = &h->dtahe_data; 18616ff6d951SJohn Birrell 18626ff6d951SJohn Birrell if (aggdata->dtada_percpu != NULL) { 18636ff6d951SJohn Birrell for (i = 0; i < max_cpus; i++) 18646ff6d951SJohn Birrell free(aggdata->dtada_percpu[i]); 18656ff6d951SJohn Birrell free(aggdata->dtada_percpu); 18666ff6d951SJohn Birrell } 18676ff6d951SJohn Birrell 18686ff6d951SJohn Birrell free(aggdata->dtada_data); 18696ff6d951SJohn Birrell free(h); 18706ff6d951SJohn Birrell } 18716ff6d951SJohn Birrell 18726ff6d951SJohn Birrell hash->dtah_hash = NULL; 18736ff6d951SJohn Birrell hash->dtah_all = NULL; 18746ff6d951SJohn Birrell hash->dtah_size = 0; 18756ff6d951SJohn Birrell } 18766ff6d951SJohn Birrell 18776ff6d951SJohn Birrell free(agp->dtat_buf.dtbd_data); 18786ff6d951SJohn Birrell free(agp->dtat_cpus); 18796ff6d951SJohn Birrell } 1880