-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ON-16037: added functions to read stats for interfaces
- Loading branch information
Richard Drinkwater
committed
Jan 23, 2025
1 parent
ebb51d9
commit cb554e6
Showing
5 changed files
with
241 additions
and
21 deletions.
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,81 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
/* SPDX-FileCopyrightText: (c) Advanced Micro Devices, Inc. */ | ||
/**************************************************************************\ | ||
*//*! \file | ||
** \brief TCPDirect stats API | ||
*//* | ||
\**************************************************************************/ | ||
|
||
#ifndef __ZF_STATS_H__ | ||
#define __ZF_STATS_H__ | ||
|
||
#ifndef __IN_ZF_TOP_H__ | ||
# error "Please include zf.h to use TCPDirect." | ||
#endif | ||
|
||
#include <etherfabric/vi.h> | ||
|
||
typedef ef_vi_stats_field_layout zf_stats_field_layout; | ||
typedef ef_vi_stats_layout zf_stats_layout; | ||
|
||
/*! \brief */ | ||
typedef struct { | ||
/** Number of underlying interfaces present in stack */ | ||
int num_intfs; | ||
/** Size of memory needed to query the stats in bytes */ | ||
int total_data_size; | ||
/** Array of layouts, one per interface */ | ||
zf_stats_layout** layout; | ||
} zf_layout_collection; | ||
|
||
/*! \brief Allocate and retrieve layout for available statistics | ||
** | ||
** \param stack The stack to query. | ||
** \param collection Pointer to an zf_layout_collection, that is allocated and | ||
** updated on return with the layout for available | ||
** statistics. This must be released when no longer needed | ||
** using zf_stats_free_layout_collection(). | ||
** | ||
** \return Zero on success or negative error code. | ||
** | ||
** Retrieve layout for available statistics. | ||
*/ | ||
ZF_LIBENTRY int | ||
zf_stats_alloc_layout_collection(struct zf_stack* stack, | ||
zf_layout_collection** collection); | ||
|
||
/*! \brief Release the layout allocated by zf_stats_alloc_query_layout(). | ||
** | ||
** \param collection Pointer to an zf_layout_collection that was allocated | ||
** using zf_stats_alloc_layout_collection(). | ||
*/ | ||
ZF_LIBENTRY void | ||
zf_stats_free_layout_collection(zf_layout_collection* collection); | ||
|
||
/*! \brief Retrieve a set of statistic values | ||
** | ||
** \param stack The stack to query. | ||
** \param data Pointer to a buffer, into which the statistics are | ||
** retrieved. | ||
** The size of this buffer must be equal to the value of | ||
** total_data_size in the zf_layout_collection structure. | ||
** \param collection Pointer to a zf_layout_collection, that was allocated for | ||
** this stack by zf_stats_alloc_layout_collection. | ||
** \param do_reset True to reset the statistics after retrieving them. | ||
** | ||
** \return zero or a negative error code. | ||
** | ||
** Retrieve a set of statistic values. | ||
** | ||
** If do_reset is true, the statistics are reset after reading. | ||
** | ||
** \note This requires full feature firmware. If used with low-latency | ||
** firmware, no error is given, and the statistics are invalid (typically | ||
** all zeroes). | ||
*/ | ||
ZF_LIBENTRY int zf_stats_query(struct zf_stack* stack, void* data, | ||
zf_layout_collection* collection, | ||
int do_reset); | ||
|
||
#endif /* __ZF_STATS_H__ */ | ||
/** @} */ |
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,68 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
/* SPDX-FileCopyrightText: (c) Advanced Micro Devices, Inc. */ | ||
#include <zf_internal/zf_stack.h> | ||
|
||
int | ||
zf_stats_alloc_layout_collection(struct zf_stack* stack, | ||
zf_layout_collection** collection) | ||
{ | ||
int i, rc = 0; | ||
int num_nics = stack->nics_n; | ||
zf_layout_collection* c; | ||
|
||
c = (zf_layout_collection*) malloc(sizeof(*c)); | ||
if( c == NULL ) | ||
return -ENOMEM; | ||
|
||
c->layout = (zf_stats_layout**) malloc(sizeof(*c->layout) * num_nics); | ||
if( c->layout == NULL ) { | ||
free(c); | ||
return -ENOMEM; | ||
} | ||
c->num_intfs = num_nics; | ||
c->total_data_size = 0; | ||
|
||
for( i = 0; i < num_nics && rc == 0; i++ ) { | ||
ef_vi* vi = &stack->nic[i].vi; | ||
rc = ef_vi_stats_query_layout(vi, | ||
(const ef_vi_stats_layout** const) &c->layout[i]); | ||
if( rc == 0 ) | ||
c->total_data_size += c->layout[i]->evsl_data_size; | ||
} | ||
|
||
|
||
if( rc < 0 ) { | ||
zf_stats_free_layout_collection(c); | ||
return rc; | ||
} | ||
*collection = c; | ||
return 0; | ||
} | ||
|
||
|
||
void | ||
zf_stats_free_layout_collection(zf_layout_collection* collection) | ||
{ | ||
free(collection->layout); | ||
free(collection); | ||
} | ||
|
||
|
||
int | ||
zf_stats_query(struct zf_stack* stack, void* data, | ||
zf_layout_collection* collection, int do_reset) | ||
{ | ||
int i, rc = 0; | ||
int num_intfs = stack->nics_n; | ||
char* pData = (char*)data; | ||
|
||
assert(num_intfs == collection->num_intfs); | ||
|
||
for( i = 0; i < num_intfs && rc == 0; i++ ) { | ||
ef_vi* vi = &stack->nic[i].vi; | ||
rc = ef_vi_stats_query(vi, vi->dh, (void*)pData, do_reset); | ||
pData += collection->layout[i]->evsl_data_size; | ||
} | ||
|
||
return rc; | ||
} |
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