Skip to content

Commit eda5891

Browse files
committed
Merge branch 'ena-driver-metrics-changes'
David Arinzon says: ==================== ENA driver metrics changes This patchset contains an introduction of new metrics available to ENA users. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 46ae4d0 + 403cdc4 commit eda5891

File tree

7 files changed

+442
-68
lines changed

7 files changed

+442
-68
lines changed

Documentation/networking/device_drivers/ethernet/amazon/ena.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ per-queue stats) from the device.
230230

231231
In addition the driver logs the stats to syslog upon device reset.
232232

233+
On supported instance types, the statistics will also include the
234+
ENA Express data (fields prefixed with `ena_srd`). For a complete
235+
documentation of ENA Express data refer to
236+
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ena-express.html#ena-express-monitor
237+
233238
MTU
234239
===
235240

drivers/net/ethernet/amazon/ena/ena_admin_defs.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77

88
#define ENA_ADMIN_RSS_KEY_PARTS 10
99

10+
#define ENA_ADMIN_CUSTOMER_METRICS_SUPPORT_MASK 0x3F
11+
#define ENA_ADMIN_CUSTOMER_METRICS_MIN_SUPPORT_MASK 0x1F
12+
13+
/* customer metrics - in correlation with
14+
* ENA_ADMIN_CUSTOMER_METRICS_SUPPORT_MASK
15+
*/
16+
enum ena_admin_customer_metrics_id {
17+
ENA_ADMIN_BW_IN_ALLOWANCE_EXCEEDED = 0,
18+
ENA_ADMIN_BW_OUT_ALLOWANCE_EXCEEDED = 1,
19+
ENA_ADMIN_PPS_ALLOWANCE_EXCEEDED = 2,
20+
ENA_ADMIN_CONNTRACK_ALLOWANCE_EXCEEDED = 3,
21+
ENA_ADMIN_LINKLOCAL_ALLOWANCE_EXCEEDED = 4,
22+
ENA_ADMIN_CONNTRACK_ALLOWANCE_AVAILABLE = 5,
23+
};
24+
1025
enum ena_admin_aq_opcode {
1126
ENA_ADMIN_CREATE_SQ = 1,
1227
ENA_ADMIN_DESTROY_SQ = 2,
@@ -51,6 +66,9 @@ enum ena_admin_aq_feature_id {
5166
/* device capabilities */
5267
enum ena_admin_aq_caps_id {
5368
ENA_ADMIN_ENI_STATS = 0,
69+
/* ENA SRD customer metrics */
70+
ENA_ADMIN_ENA_SRD_INFO = 1,
71+
ENA_ADMIN_CUSTOMER_METRICS = 2,
5472
};
5573

5674
enum ena_admin_placement_policy_type {
@@ -99,13 +117,26 @@ enum ena_admin_get_stats_type {
99117
ENA_ADMIN_GET_STATS_TYPE_EXTENDED = 1,
100118
/* extra HW stats for specific network interface */
101119
ENA_ADMIN_GET_STATS_TYPE_ENI = 2,
120+
/* extra HW stats for ENA SRD */
121+
ENA_ADMIN_GET_STATS_TYPE_ENA_SRD = 3,
122+
ENA_ADMIN_GET_STATS_TYPE_CUSTOMER_METRICS = 4,
102123
};
103124

104125
enum ena_admin_get_stats_scope {
105126
ENA_ADMIN_SPECIFIC_QUEUE = 0,
106127
ENA_ADMIN_ETH_TRAFFIC = 1,
107128
};
108129

130+
/* ENA SRD configuration for ENI */
131+
enum ena_admin_ena_srd_flags {
132+
/* Feature enabled */
133+
ENA_ADMIN_ENA_SRD_ENABLED = BIT(0),
134+
/* UDP support enabled */
135+
ENA_ADMIN_ENA_SRD_UDP_ENABLED = BIT(1),
136+
/* Bypass Rx UDP ordering */
137+
ENA_ADMIN_ENA_SRD_UDP_ORDERING_BYPASS_ENABLED = BIT(2),
138+
};
139+
109140
struct ena_admin_aq_common_desc {
110141
/* 11:0 : command_id
111142
* 15:12 : reserved12
@@ -363,6 +394,9 @@ struct ena_admin_aq_get_stats_cmd {
363394
* stats of other device
364395
*/
365396
u16 device_id;
397+
398+
/* a bitmap representing the requested metric values */
399+
u64 requested_metrics;
366400
};
367401

368402
/* Basic Statistics Command. */
@@ -419,6 +453,40 @@ struct ena_admin_eni_stats {
419453
u64 linklocal_allowance_exceeded;
420454
};
421455

456+
struct ena_admin_ena_srd_stats {
457+
/* Number of packets transmitted over ENA SRD */
458+
u64 ena_srd_tx_pkts;
459+
460+
/* Number of packets transmitted or could have been
461+
* transmitted over ENA SRD
462+
*/
463+
u64 ena_srd_eligible_tx_pkts;
464+
465+
/* Number of packets received over ENA SRD */
466+
u64 ena_srd_rx_pkts;
467+
468+
/* Percentage of the ENA SRD resources that is in use */
469+
u64 ena_srd_resource_utilization;
470+
};
471+
472+
/* ENA SRD Statistics Command */
473+
struct ena_admin_ena_srd_info {
474+
/* ENA SRD configuration bitmap. See ena_admin_ena_srd_flags for
475+
* details
476+
*/
477+
u64 flags;
478+
479+
struct ena_admin_ena_srd_stats ena_srd_stats;
480+
};
481+
482+
/* Customer Metrics Command. */
483+
struct ena_admin_customer_metrics {
484+
/* A bitmap representing the reported customer metrics according to
485+
* the order they are reported
486+
*/
487+
u64 reported_metrics;
488+
};
489+
422490
struct ena_admin_acq_get_stats_resp {
423491
struct ena_admin_acq_common_desc acq_common_desc;
424492

@@ -428,6 +496,10 @@ struct ena_admin_acq_get_stats_resp {
428496
struct ena_admin_basic_stats basic_stats;
429497

430498
struct ena_admin_eni_stats eni_stats;
499+
500+
struct ena_admin_ena_srd_info ena_srd_info;
501+
502+
struct ena_admin_customer_metrics customer_metrics;
431503
} u;
432504
};
433505

drivers/net/ethernet/amazon/ena/ena_com.c

Lines changed: 147 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,56 @@ int ena_com_get_link_params(struct ena_com_dev *ena_dev,
18811881
return ena_com_get_feature(ena_dev, resp, ENA_ADMIN_LINK_CONFIG, 0);
18821882
}
18831883

1884+
static int ena_get_dev_stats(struct ena_com_dev *ena_dev,
1885+
struct ena_com_stats_ctx *ctx,
1886+
enum ena_admin_get_stats_type type)
1887+
{
1888+
struct ena_admin_acq_get_stats_resp *get_resp = &ctx->get_resp;
1889+
struct ena_admin_aq_get_stats_cmd *get_cmd = &ctx->get_cmd;
1890+
struct ena_com_admin_queue *admin_queue;
1891+
int ret;
1892+
1893+
admin_queue = &ena_dev->admin_queue;
1894+
1895+
get_cmd->aq_common_descriptor.opcode = ENA_ADMIN_GET_STATS;
1896+
get_cmd->aq_common_descriptor.flags = 0;
1897+
get_cmd->type = type;
1898+
1899+
ret = ena_com_execute_admin_command(admin_queue,
1900+
(struct ena_admin_aq_entry *)get_cmd,
1901+
sizeof(*get_cmd),
1902+
(struct ena_admin_acq_entry *)get_resp,
1903+
sizeof(*get_resp));
1904+
1905+
if (unlikely(ret))
1906+
netdev_err(ena_dev->net_device, "Failed to get stats. error: %d\n", ret);
1907+
1908+
return ret;
1909+
}
1910+
1911+
static void ena_com_set_supported_customer_metrics(struct ena_com_dev *ena_dev)
1912+
{
1913+
struct ena_customer_metrics *customer_metrics;
1914+
struct ena_com_stats_ctx ctx;
1915+
int ret;
1916+
1917+
customer_metrics = &ena_dev->customer_metrics;
1918+
if (!ena_com_get_cap(ena_dev, ENA_ADMIN_CUSTOMER_METRICS)) {
1919+
customer_metrics->supported_metrics = ENA_ADMIN_CUSTOMER_METRICS_MIN_SUPPORT_MASK;
1920+
return;
1921+
}
1922+
1923+
memset(&ctx, 0x0, sizeof(ctx));
1924+
ctx.get_cmd.requested_metrics = ENA_ADMIN_CUSTOMER_METRICS_SUPPORT_MASK;
1925+
ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_CUSTOMER_METRICS);
1926+
if (likely(ret == 0))
1927+
customer_metrics->supported_metrics =
1928+
ctx.get_resp.u.customer_metrics.reported_metrics;
1929+
else
1930+
netdev_err(ena_dev->net_device,
1931+
"Failed to query customer metrics support. error: %d\n", ret);
1932+
}
1933+
18841934
int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
18851935
struct ena_com_dev_get_features_ctx *get_feat_ctx)
18861936
{
@@ -1960,6 +2010,8 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
19602010
else
19612011
return rc;
19622012

2013+
ena_com_set_supported_customer_metrics(ena_dev);
2014+
19632015
return 0;
19642016
}
19652017

@@ -2104,50 +2156,44 @@ int ena_com_dev_reset(struct ena_com_dev *ena_dev,
21042156
return 0;
21052157
}
21062158

2107-
static int ena_get_dev_stats(struct ena_com_dev *ena_dev,
2108-
struct ena_com_stats_ctx *ctx,
2109-
enum ena_admin_get_stats_type type)
2159+
int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
2160+
struct ena_admin_eni_stats *stats)
21102161
{
2111-
struct ena_admin_aq_get_stats_cmd *get_cmd = &ctx->get_cmd;
2112-
struct ena_admin_acq_get_stats_resp *get_resp = &ctx->get_resp;
2113-
struct ena_com_admin_queue *admin_queue;
2162+
struct ena_com_stats_ctx ctx;
21142163
int ret;
21152164

2116-
admin_queue = &ena_dev->admin_queue;
2117-
2118-
get_cmd->aq_common_descriptor.opcode = ENA_ADMIN_GET_STATS;
2119-
get_cmd->aq_common_descriptor.flags = 0;
2120-
get_cmd->type = type;
2121-
2122-
ret = ena_com_execute_admin_command(admin_queue,
2123-
(struct ena_admin_aq_entry *)get_cmd,
2124-
sizeof(*get_cmd),
2125-
(struct ena_admin_acq_entry *)get_resp,
2126-
sizeof(*get_resp));
2165+
if (!ena_com_get_cap(ena_dev, ENA_ADMIN_ENI_STATS)) {
2166+
netdev_err(ena_dev->net_device, "Capability %d isn't supported\n",
2167+
ENA_ADMIN_ENI_STATS);
2168+
return -EOPNOTSUPP;
2169+
}
21272170

2128-
if (unlikely(ret))
2129-
netdev_err(ena_dev->net_device, "Failed to get stats. error: %d\n", ret);
2171+
memset(&ctx, 0x0, sizeof(ctx));
2172+
ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_ENI);
2173+
if (likely(ret == 0))
2174+
memcpy(stats, &ctx.get_resp.u.eni_stats,
2175+
sizeof(ctx.get_resp.u.eni_stats));
21302176

21312177
return ret;
21322178
}
21332179

2134-
int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
2135-
struct ena_admin_eni_stats *stats)
2180+
int ena_com_get_ena_srd_info(struct ena_com_dev *ena_dev,
2181+
struct ena_admin_ena_srd_info *info)
21362182
{
21372183
struct ena_com_stats_ctx ctx;
21382184
int ret;
21392185

2140-
if (!ena_com_get_cap(ena_dev, ENA_ADMIN_ENI_STATS)) {
2186+
if (!ena_com_get_cap(ena_dev, ENA_ADMIN_ENA_SRD_INFO)) {
21412187
netdev_err(ena_dev->net_device, "Capability %d isn't supported\n",
2142-
ENA_ADMIN_ENI_STATS);
2188+
ENA_ADMIN_ENA_SRD_INFO);
21432189
return -EOPNOTSUPP;
21442190
}
21452191

21462192
memset(&ctx, 0x0, sizeof(ctx));
2147-
ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_ENI);
2193+
ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_ENA_SRD);
21482194
if (likely(ret == 0))
2149-
memcpy(stats, &ctx.get_resp.u.eni_stats,
2150-
sizeof(ctx.get_resp.u.eni_stats));
2195+
memcpy(info, &ctx.get_resp.u.ena_srd_info,
2196+
sizeof(ctx.get_resp.u.ena_srd_info));
21512197

21522198
return ret;
21532199
}
@@ -2167,6 +2213,50 @@ int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
21672213
return ret;
21682214
}
21692215

2216+
int ena_com_get_customer_metrics(struct ena_com_dev *ena_dev, char *buffer, u32 len)
2217+
{
2218+
struct ena_admin_aq_get_stats_cmd *get_cmd;
2219+
struct ena_com_stats_ctx ctx;
2220+
int ret;
2221+
2222+
if (unlikely(len > ena_dev->customer_metrics.buffer_len)) {
2223+
netdev_err(ena_dev->net_device,
2224+
"Invalid buffer size %u. The given buffer is too big.\n", len);
2225+
return -EINVAL;
2226+
}
2227+
2228+
if (!ena_com_get_cap(ena_dev, ENA_ADMIN_CUSTOMER_METRICS)) {
2229+
netdev_err(ena_dev->net_device, "Capability %d not supported.\n",
2230+
ENA_ADMIN_CUSTOMER_METRICS);
2231+
return -EOPNOTSUPP;
2232+
}
2233+
2234+
if (!ena_dev->customer_metrics.supported_metrics) {
2235+
netdev_err(ena_dev->net_device, "No supported customer metrics.\n");
2236+
return -EOPNOTSUPP;
2237+
}
2238+
2239+
get_cmd = &ctx.get_cmd;
2240+
memset(&ctx, 0x0, sizeof(ctx));
2241+
ret = ena_com_mem_addr_set(ena_dev,
2242+
&get_cmd->u.control_buffer.address,
2243+
ena_dev->customer_metrics.buffer_dma_addr);
2244+
if (unlikely(ret)) {
2245+
netdev_err(ena_dev->net_device, "Memory address set failed.\n");
2246+
return ret;
2247+
}
2248+
2249+
get_cmd->u.control_buffer.length = ena_dev->customer_metrics.buffer_len;
2250+
get_cmd->requested_metrics = ena_dev->customer_metrics.supported_metrics;
2251+
ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_CUSTOMER_METRICS);
2252+
if (likely(ret == 0))
2253+
memcpy(buffer, ena_dev->customer_metrics.buffer_virt_addr, len);
2254+
else
2255+
netdev_err(ena_dev->net_device, "Failed to get customer metrics. error: %d\n", ret);
2256+
2257+
return ret;
2258+
}
2259+
21702260
int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, u32 mtu)
21712261
{
21722262
struct ena_com_admin_queue *admin_queue;
@@ -2706,6 +2796,24 @@ int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
27062796
return 0;
27072797
}
27082798

2799+
int ena_com_allocate_customer_metrics_buffer(struct ena_com_dev *ena_dev)
2800+
{
2801+
struct ena_customer_metrics *customer_metrics = &ena_dev->customer_metrics;
2802+
2803+
customer_metrics->buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE;
2804+
customer_metrics->buffer_virt_addr = NULL;
2805+
2806+
customer_metrics->buffer_virt_addr =
2807+
dma_alloc_coherent(ena_dev->dmadev, customer_metrics->buffer_len,
2808+
&customer_metrics->buffer_dma_addr, GFP_KERNEL);
2809+
if (!customer_metrics->buffer_virt_addr) {
2810+
customer_metrics->buffer_len = 0;
2811+
return -ENOMEM;
2812+
}
2813+
2814+
return 0;
2815+
}
2816+
27092817
void ena_com_delete_host_info(struct ena_com_dev *ena_dev)
27102818
{
27112819
struct ena_host_attribute *host_attr = &ena_dev->host_attr;
@@ -2728,6 +2836,19 @@ void ena_com_delete_debug_area(struct ena_com_dev *ena_dev)
27282836
}
27292837
}
27302838

2839+
void ena_com_delete_customer_metrics_buffer(struct ena_com_dev *ena_dev)
2840+
{
2841+
struct ena_customer_metrics *customer_metrics = &ena_dev->customer_metrics;
2842+
2843+
if (customer_metrics->buffer_virt_addr) {
2844+
dma_free_coherent(ena_dev->dmadev, customer_metrics->buffer_len,
2845+
customer_metrics->buffer_virt_addr,
2846+
customer_metrics->buffer_dma_addr);
2847+
customer_metrics->buffer_virt_addr = NULL;
2848+
customer_metrics->buffer_len = 0;
2849+
}
2850+
}
2851+
27312852
int ena_com_set_host_attributes(struct ena_com_dev *ena_dev)
27322853
{
27332854
struct ena_host_attribute *host_attr = &ena_dev->host_attr;

0 commit comments

Comments
 (0)