-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code for quantize() aggregation function
First, quantize the value into a 0-based bin number. While we could generate BPF code in dt_cg.c to accomplish this, it is easier to maintain C code in the bpf/ subdirectory to be cross-compiled into BPF when DTrace is built. Then, the "implementation" function -- which needs to run twice, once per aggregation copy -- merely updates the value in the designated bin. This "implementation" can be used for lquantize() and llquantize() as well. For that matter, it could be used for other aggregations such as sum(), though that special case has only one bin. The function tests the bin number against 0 and some maxbin, both as a safety check and because the BPF verifier needs such assurances in certain cases. Signed-off-by: Eugene Loh <eugene.loh@oracle.com> Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
- Loading branch information
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
*/ | ||
#include <linux/bpf.h> | ||
#include <stdint.h> | ||
#include <bpf-helpers.h> | ||
|
||
#ifndef noinline | ||
# define noinline __attribute__((noinline)) | ||
#endif | ||
|
||
noinline int16_t dt_agg_qbin(int64_t val) | ||
{ | ||
int16_t off; | ||
uint64_t tmp; | ||
|
||
if (val == 0) | ||
return 63; | ||
if (val == 0x8000000000000000) | ||
return 0; | ||
|
||
tmp = val; | ||
if (val < 0) | ||
tmp *= -1; | ||
|
||
/* now, tmp has at least one 1, while the leading bit is 0 */ | ||
off = 1; | ||
if (tmp & 0x7fffffff00000000) { off += 32; tmp >>= 32; } | ||
if (tmp & 0x00000000ffff0000) { off += 16; tmp >>= 16; } | ||
if (tmp & 0x000000000000ff00) { off += 8; tmp >>= 8; } | ||
if (tmp & 0x00000000000000f0) { off += 4; tmp >>= 4; } | ||
if (tmp & 0x000000000000000c) { off += 2; tmp >>= 2; } | ||
if (tmp & 0x0000000000000002) { off += 1; } | ||
|
||
if (val < 0) | ||
off *= -1; | ||
off += 63; | ||
return off; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters