Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Linux/tools/testing/selftests/bpf/progs/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 1 kB image not shown  

Quelle  test_ringbuf_map_key.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

char _license[] SEC("license") = "GPL";

struct sample {
 int pid;
 int seq;
 long value;
 char comm[16];
};

struct {
 __uint(type, BPF_MAP_TYPE_RINGBUF);
} ringbuf SEC(".maps");

struct {
 __uint(type, BPF_MAP_TYPE_HASH);
 __uint(max_entries, 1000);
 __type(key, struct sample);
 __type(value, int);
} hash_map SEC(".maps");

/* inputs */
int pid = 0;

/* inner state */
long seq = 0;

SEC("fentry/" SYS_PREFIX "sys_getpgid")
int test_ringbuf_mem_map_key(void *ctx)
{
 int cur_pid = bpf_get_current_pid_tgid() >> 32;
 struct sample *sample, sample_copy;
 int *lookup_val;

 if (cur_pid != pid)
  return 0;

 sample = bpf_ringbuf_reserve(&ringbuf, sizeof(*sample), 0);
 if (!sample)
  return 0;

 sample->pid = pid;
 bpf_get_current_comm(sample->comm, sizeof(sample->comm));
 sample->seq = ++seq;
 sample->value = 42;

 /* test using 'sample' (PTR_TO_MEM | MEM_ALLOC) as map key arg
 */

 lookup_val = (int *)bpf_map_lookup_elem(&hash_map, sample);
 __sink(lookup_val);

 /* workaround - memcpy is necessary so that verifier doesn't
 * complain with:
 *   verifier internal error: more than one arg with ref_obj_id R3
 * when trying to do bpf_map_update_elem(&hash_map, sample, &sample->seq, BPF_ANY);
 *
 * Since bpf_map_lookup_elem above uses 'sample' as key, test using
 * sample field as value below
 */

 __builtin_memcpy(&sample_copy, sample, sizeof(struct sample));
 bpf_map_update_elem(&hash_map, &sample_copy, &sample->seq, BPF_ANY);

 bpf_ringbuf_submit(sample, 0);
 return 0;
}

Messung V0.5
C=99 H=99 G=98

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.