linux_old1/kernel/trace/tracing_map.h

278 lines
11 KiB
C
Raw Normal View History

License cleanup: add SPDX GPL-2.0 license identifier to files with no license Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __TRACING_MAP_H
#define __TRACING_MAP_H
#define TRACING_MAP_BITS_DEFAULT 11
#define TRACING_MAP_BITS_MAX 17
#define TRACING_MAP_BITS_MIN 7
#define TRACING_MAP_KEYS_MAX 3
#define TRACING_MAP_VALS_MAX 3
#define TRACING_MAP_FIELDS_MAX (TRACING_MAP_KEYS_MAX + \
TRACING_MAP_VALS_MAX)
#define TRACING_MAP_SORT_KEYS_MAX 2
typedef int (*tracing_map_cmp_fn_t) (void *val_a, void *val_b);
/*
* This is an overview of the tracing_map data structures and how they
* relate to the tracing_map API. The details of the algorithms
* aren't discussed here - this is just a general overview of the data
* structures and how they interact with the API.
*
* The central data structure of the tracing_map is an initially
* zeroed array of struct tracing_map_entry (stored in the map field
* of struct tracing_map). tracing_map_entry is a very simple data
* structure containing only two fields: a 32-bit unsigned 'key'
* variable and a pointer named 'val'. This array of struct
* tracing_map_entry is essentially a hash table which will be
* modified by a single function, tracing_map_insert(), but which can
* be traversed and read by a user at any time (though the user does
* this indirectly via an array of tracing_map_sort_entry - see the
* explanation of that data structure in the discussion of the
* sorting-related data structures below).
*
* The central function of the tracing_map API is
* tracing_map_insert(). tracing_map_insert() hashes the
* arbitrarily-sized key passed into it into a 32-bit unsigned key.
* It then uses this key, truncated to the array size, as an index
* into the array of tracing_map_entries. If the value of the 'key'
* field of the tracing_map_entry found at that location is 0, then
* that entry is considered to be free and can be claimed, by
* replacing the 0 in the 'key' field of the tracing_map_entry with
* the new 32-bit hashed key. Once claimed, that tracing_map_entry's
* 'val' field is then used to store a unique element which will be
* forever associated with that 32-bit hashed key in the
* tracing_map_entry.
*
* That unique element now in the tracing_map_entry's 'val' field is
* an instance of tracing_map_elt, where 'elt' in the latter part of
* that variable name is short for 'element'. The purpose of a
* tracing_map_elt is to hold values specific to the particular
* 32-bit hashed key it's assocated with. Things such as the unique
* set of aggregated sums associated with the 32-bit hashed key, along
* with a copy of the full key associated with the entry, and which
* was used to produce the 32-bit hashed key.
*
* When tracing_map_create() is called to create the tracing map, the
* user specifies (indirectly via the map_bits param, the details are
* unimportant for this discussion) the maximum number of elements
* that the map can hold (stored in the max_elts field of struct
* tracing_map). This is the maximum possible number of
* tracing_map_entries in the tracing_map_entry array which can be
* 'claimed' as described in the above discussion, and therefore is
* also the maximum number of tracing_map_elts that can be associated
* with the tracing_map_entry array in the tracing_map. Because of
* the way the insertion algorithm works, the size of the allocated
* tracing_map_entry array is always twice the maximum number of
* elements (2 * max_elts). This value is stored in the map_size
* field of struct tracing_map.
*
* Because tracing_map_insert() needs to work from any context,
* including from within the memory allocation functions themselves,
* both the tracing_map_entry array and a pool of max_elts
* tracing_map_elts are pre-allocated before any call is made to
* tracing_map_insert().
*
* The tracing_map_entry array is allocated as a single block by
* tracing_map_create().
*
* Because the tracing_map_elts are much larger objects and can't
* generally be allocated together as a single large array without
* failure, they're allocated individually, by tracing_map_init().
*
* The pool of tracing_map_elts are allocated by tracing_map_init()
* rather than by tracing_map_create() because at the time
* tracing_map_create() is called, there isn't enough information to
* create the tracing_map_elts. Specifically,the user first needs to
* tell the tracing_map implementation how many fields the
* tracing_map_elts contain, and which types of fields they are (key
* or sum). The user does this via the tracing_map_add_sum_field()
* and tracing_map_add_key_field() functions, following which the user
* calls tracing_map_init() to finish up the tracing map setup. The
* array holding the pointers which make up the pre-allocated pool of
* tracing_map_elts is allocated as a single block and is stored in
* the elts field of struct tracing_map.
*
* There is also a set of structures used for sorting that might
* benefit from some minimal explanation.
*
* struct tracing_map_sort_key is used to drive the sort at any given
* time. By 'any given time' we mean that a different
* tracing_map_sort_key will be used at different times depending on
* whether the sort currently being performed is a primary or a
* secondary sort.
*
* The sort key is very simple, consisting of the field index of the
* tracing_map_elt field to sort on (which the user saved when adding
* the field), and whether the sort should be done in an ascending or
* descending order.
*
* For the convenience of the sorting code, a tracing_map_sort_entry
* is created for each tracing_map_elt, again individually allocated
* to avoid failures that might be expected if allocated as a single
* large array of struct tracing_map_sort_entry.
* tracing_map_sort_entry instances are the objects expected by the
* various internal sorting functions, and are also what the user
* ultimately receives after calling tracing_map_sort_entries().
* Because it doesn't make sense for users to access an unordered and
* sparsely populated tracing_map directly, the
* tracing_map_sort_entries() function is provided so that users can
* retrieve a sorted list of all existing elements. In addition to
* the associated tracing_map_elt 'elt' field contained within the
* tracing_map_sort_entry, which is the object of interest to the
* user, tracing_map_sort_entry objects contain a number of additional
* fields which are used for caching and internal purposes and can
* safely be ignored.
*/
struct tracing_map_field {
tracing_map_cmp_fn_t cmp_fn;
union {
atomic64_t sum;
unsigned int offset;
};
};
struct tracing_map_elt {
struct tracing_map *map;
struct tracing_map_field *fields;
void *key;
void *private_data;
};
struct tracing_map_entry {
u32 key;
struct tracing_map_elt *val;
};
struct tracing_map_sort_key {
unsigned int field_idx;
bool descending;
};
struct tracing_map_sort_entry {
void *key;
struct tracing_map_elt *elt;
bool elt_copied;
bool dup;
};
struct tracing_map_array {
unsigned int entries_per_page;
unsigned int entry_size_shift;
unsigned int entry_shift;
unsigned int entry_mask;
unsigned int n_pages;
void **pages;
};
#define TRACING_MAP_ARRAY_ELT(array, idx) \
(array->pages[idx >> array->entry_shift] + \
((idx & array->entry_mask) << array->entry_size_shift))
#define TRACING_MAP_ENTRY(array, idx) \
((struct tracing_map_entry *)TRACING_MAP_ARRAY_ELT(array, idx))
#define TRACING_MAP_ELT(array, idx) \
((struct tracing_map_elt **)TRACING_MAP_ARRAY_ELT(array, idx))
struct tracing_map {
unsigned int key_size;
unsigned int map_bits;
unsigned int map_size;
unsigned int max_elts;
atomic_t next_elt;
struct tracing_map_array *elts;
struct tracing_map_array *map;
const struct tracing_map_ops *ops;
void *private_data;
struct tracing_map_field fields[TRACING_MAP_FIELDS_MAX];
unsigned int n_fields;
int key_idx[TRACING_MAP_KEYS_MAX];
unsigned int n_keys;
struct tracing_map_sort_key sort_key;
atomic64_t hits;
atomic64_t drops;
};
/**
* struct tracing_map_ops - callbacks for tracing_map
*
* The methods in this structure define callback functions for various
* operations on a tracing_map or objects related to a tracing_map.
*
* For a detailed description of tracing_map_elt objects please see
* the overview of tracing_map data structures at the beginning of
* this file.
*
* All the methods below are optional.
*
* @elt_alloc: When a tracing_map_elt is allocated, this function, if
* defined, will be called and gives clients the opportunity to
* allocate additional data and attach it to the element
* (tracing_map_elt->private_data is meant for that purpose).
* Element allocation occurs before tracing begins, when the
* tracing_map_init() call is made by client code.
*
* @elt_free: When a tracing_map_elt is freed, this function is called
* and allows client-allocated per-element data to be freed.
*
* @elt_clear: This callback allows per-element client-defined data to
* be cleared, if applicable.
*
* @elt_init: This callback allows per-element client-defined data to
* be initialized when used i.e. when the element is actually
* claimed by tracing_map_insert() in the context of the map
* insertion.
*/
struct tracing_map_ops {
int (*elt_alloc)(struct tracing_map_elt *elt);
void (*elt_free)(struct tracing_map_elt *elt);
void (*elt_clear)(struct tracing_map_elt *elt);
void (*elt_init)(struct tracing_map_elt *elt);
};
extern struct tracing_map *
tracing_map_create(unsigned int map_bits,
unsigned int key_size,
const struct tracing_map_ops *ops,
void *private_data);
extern int tracing_map_init(struct tracing_map *map);
extern int tracing_map_add_sum_field(struct tracing_map *map);
extern int tracing_map_add_key_field(struct tracing_map *map,
unsigned int offset,
tracing_map_cmp_fn_t cmp_fn);
extern void tracing_map_destroy(struct tracing_map *map);
extern void tracing_map_clear(struct tracing_map *map);
extern struct tracing_map_elt *
tracing_map_insert(struct tracing_map *map, void *key);
extern struct tracing_map_elt *
tracing_map_lookup(struct tracing_map *map, void *key);
extern tracing_map_cmp_fn_t tracing_map_cmp_num(int field_size,
int field_is_signed);
extern int tracing_map_cmp_string(void *val_a, void *val_b);
extern int tracing_map_cmp_none(void *val_a, void *val_b);
extern void tracing_map_update_sum(struct tracing_map_elt *elt,
unsigned int i, u64 n);
extern u64 tracing_map_read_sum(struct tracing_map_elt *elt, unsigned int i);
extern void tracing_map_set_field_descr(struct tracing_map *map,
unsigned int i,
unsigned int key_offset,
tracing_map_cmp_fn_t cmp_fn);
extern int
tracing_map_sort_entries(struct tracing_map *map,
struct tracing_map_sort_key *sort_keys,
unsigned int n_sort_keys,
struct tracing_map_sort_entry ***sort_entries);
extern void
tracing_map_destroy_sort_entries(struct tracing_map_sort_entry **entries,
unsigned int n_entries);
#endif /* __TRACING_MAP_H */