<commit_before>// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 <NAME>
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_tracing.h>
#include "biolatency.h"
#include "bits.bpf.h"

#define MAX_ENTRIES	10240

const volatile bool targ_per_disk = false;
const volatile bool targ_per_flag = false;
const volatile bool targ_queued = false;
const volatile bool targ_ms = false;
const volatile dev_t targ_dev = -1;

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, MAX_ENTRIES);
	__type(key, struct request *);
	__type(value, u64);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} start SEC(".maps");

static struct hist initial_hist;

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, MAX_ENTRIES);
	__type(key, struct hist_key);
	__type(value, struct hist);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} hists SEC(".maps");

static __always_inline
int trace_rq_start(struct request *rq)
{
	u64 ts = bpf_ktime_get_ns();

	if (targ_dev != -1) {
		struct gendisk *disk = BPF_CORE_READ(rq, rq_disk);
		dev_t dev;

		dev = disk ? MKDEV(BPF_CORE_READ(disk, major),
				BPF_CORE_READ(disk, first_minor)) : 0;
		if (targ_dev != dev)
			return 0;
	}
	bpf_map_update_elem(&start, &rq, &ts, 0);
	return 0;
}

SEC("tp_btf/block_rq_insert")
int BPF_PROG(block_rq_insert, struct request_queue *q, struct request *rq)
{
	return trace_rq_start(rq);
}

SEC("tp_btf/block_rq_issue")
int BPF_PROG(block_rq_issue, struct request_queue *q, struct request *rq)
{
	if (targ_queued && BPF_CORE_READ(q, elevator))
		return 0;
	return trace_rq_start(rq);
}

SEC("tp_btf/block_rq_complete")
int BPF_PROG(block_rq_complete, struct request *rq, int error,
	unsigned int nr_bytes)
{
	u64 slot, *tsp, ts = bpf_ktime_get_ns();
	struct hist_key hkey = {};
	struct hist *histp;
	s64 delta;

	tsp = bpf_map_lookup_elem(&start, &rq);
	if (!tsp)
		return 0;
	delta = (s64)(ts - *tsp);
	if (delta < 0)
		goto cleanup;
<commit_msg>block tracepoints no longer have struct request_queue arg<commit_after>// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 <NAME>
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_tracing.h>
#include "biolatency.h"
#include "bits.bpf.h"
#include <linux/version.h>

#define MAX_ENTRIES	10240

const volatile bool targ_per_disk = false;
const volatile bool targ_per_flag = false;
const volatile bool targ_queued = false;
const volatile bool targ_ms = false;
const volatile dev_t targ_dev = -1;

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, MAX_ENTRIES);
	__type(key, struct request *);
	__type(value, u64);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} start SEC(".maps");

static struct hist initial_hist;

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, MAX_ENTRIES);
	__type(key, struct hist_key);
	__type(value, struct hist);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} hists SEC(".maps");

static __always_inline
int trace_rq_start(struct request *rq)
{
	u64 ts = bpf_ktime_get_ns();

	if (targ_dev != -1) {
		struct gendisk *disk = BPF_CORE_READ(rq, rq_disk);
		dev_t dev;

		dev = disk ? MKDEV(BPF_CORE_READ(disk, major),
				BPF_CORE_READ(disk, first_minor)) : 0;
		if (targ_dev != dev)
			return 0;
	}
	bpf_map_update_elem(&start, &rq, &ts, 0);
	return 0;
}

SEC("tp_btf/block_rq_insert")
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 1)
int BPF_PROG(block_rq_insert, struct request *rq)
{
	return trace_rq_start(rq);
}
#else
int BPF_PROG(block_rq_insert, struct request_queue *q, struct request *rq)
{
	return trace_rq_start(rq);
}
#endif

SEC("tp_btf/block_rq_issue")
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 1)
int BPF_PROG(block_rq_issue, struct request *rq)
{
	if (targ_queued && BPF_CORE_READ(rq->q, elevator))
		return 0;
	return trace_rq_start(rq);
}
#else
int BPF_PROG(block_rq_issue, struct request_queue *q, struct request *rq)
{
	if (targ_queued && BPF_CORE_READ(q, elevator))
		return 0;
	return trace_rq_start(rq);
}
#endif

SEC("tp_btf/block_rq_complete")
int BPF_PROG(block_rq_complete, struct request *rq, int error,
	unsigned int nr_bytes)
{
	u64 slot, *tsp, ts = bpf_ktime_get_ns();
	struct hist_key hkey = {};
	struct hist *histp;
	s64 delta;

	tsp = bpf_map_lookup_elem(&start, &rq);
	if (!tsp)
		return 0;
	delta = (s64)(ts - *tsp);
	if (delta < 0)
		goto cleanup;

{'fraction_non_alphanumeric': 0.12868324125230202, 'fraction_numerical': 0.015883977900552487, 'mean_word_length': 5.494768310911809, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5260380', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1804, 'n_words': 411}