MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bpf_rss_key

Function bpf_rss_key

dpdk/drivers/net/tap/tap_flow.c:1978–2062  ·  view source on GitHub ↗

* Manage bpf RSS keys repository with operations: init, get, release * * @param[in] cmd * Command on RSS keys: init, get, release * * @param[in, out] key_idx * Pointer to RSS Key index (out for get command, in for release command) * * @return -1 if couldn't get, release or init the RSS keys, 0 otherwise. */

Source from the content-addressed store, hash-verified

1976 * @return -1 if couldn't get, release or init the RSS keys, 0 otherwise.
1977 */
1978static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)
1979{
1980 __u32 i;
1981 int err = 0;
1982 static __u32 num_used_keys;
1983 static __u32 rss_keys[MAX_RSS_KEYS] = {KEY_STAT_UNSPEC};
1984 static __u32 rss_keys_initialized;
1985 __u32 key;
1986
1987 switch (cmd) {
1988 case KEY_CMD_GET:
1989 if (!rss_keys_initialized) {
1990 err = -1;
1991 break;
1992 }
1993
1994 if (num_used_keys == RTE_DIM(rss_keys)) {
1995 err = -1;
1996 break;
1997 }
1998
1999 *key_idx = num_used_keys % RTE_DIM(rss_keys);
2000 while (rss_keys[*key_idx] == KEY_STAT_USED)
2001 *key_idx = (*key_idx + 1) % RTE_DIM(rss_keys);
2002
2003 rss_keys[*key_idx] = KEY_STAT_USED;
2004
2005 /*
2006 * Add an offset to key_idx in order to handle a case of
2007 * RSS and non RSS flows mixture.
2008 * If a non RSS flow is destroyed it has an eBPF map
2009 * index 0 (initialized on flow creation) and might
2010 * unintentionally remove RSS entry 0 from eBPF map.
2011 * To avoid this issue, add an offset to the real index
2012 * during a KEY_CMD_GET operation and subtract this offset
2013 * during a KEY_CMD_RELEASE operation in order to restore
2014 * the real index.
2015 */
2016 *key_idx += KEY_IDX_OFFSET;
2017 num_used_keys++;
2018 break;
2019
2020 case KEY_CMD_RELEASE:
2021 if (!rss_keys_initialized)
2022 break;
2023
2024 /*
2025 * Subtract offset to restore real key index
2026 * If a non RSS flow is falsely trying to release map
2027 * entry 0 - the offset subtraction will calculate the real
2028 * map index as an out-of-range value and the release operation
2029 * will be silently ignored.
2030 */
2031 key = *key_idx - KEY_IDX_OFFSET;
2032 if (key >= RTE_DIM(rss_keys))
2033 break;
2034
2035 if (rss_keys[key] == KEY_STAT_USED) {

Callers 3

tap_flow_freeFunction · 0.85
rss_enableFunction · 0.85
rss_add_actionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected