Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAI Proposal generic resource monitoring #942

Merged
merged 11 commits into from
Jul 23, 2019
51 changes: 51 additions & 0 deletions doc/SAI-Proposal-Generic-Resource-Monitoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Switch Abstraction Interface Change Proposal
lguohan marked this conversation as resolved.
Show resolved Hide resolved

Title | Generic Resource Query
------------|----------------
Authors | Mellanox
Status | In review
Type | Standards track
Created | 04/15/2019
SAI-Version | 1.4
----------

## Overview
SAI manages ASIC resources. It is important for the user to query the current resources usage in the ASIC for different types of SAI objects.
It is also importaint to make as much resources availability exposed as possible.

## Spec

This proposal introduces an API for querying resource availability on per object basis.
```
/**
* @brief Get SAI object type resource availability.
*
* @param[in] object_type SAI object type
* @param[in] attr_count Number of attributes
* @param[in] attr_list List of attributes that to distinguish resource
* @param[out] count Available objects left
*
* @return #SAI_STATUS_NOT_SUPPORTED if the given object type does not support resource accounting.
* Otherwise, return #SAI_STATUS_SUCCESS.
*/
sai_status_t sai_object_type_get_availability(
_In_ sai_object_type_t object_type,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list,
_Out_ uint64_t *count);
```

To help distibguish between different resource pools for the same object type, attributes that are annotated with `@isresourcetype` must be passed to the function with corresponding values.
For example, different types of route entries are distinguished by the following attribute:
```
/** READ-ONLY */

/**
* @brief Route entry IP address family
*
* @type sai_ip_addr_family_t
* @flags READ_ONLY
* @isresourcetype true
*/
SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY,
```
17 changes: 17 additions & 0 deletions inc/sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ sai_object_id_t sai_switch_id_query(
sai_status_t sai_dbg_generate_dump(
_In_ const char *dump_file_name);

/**
* @brief Get SAI object type resource availability.
*
* @param[in] object_type SAI object type
* @param[in] attr_count Number of attributes
* @param[in] attr_list List of attributes that to distinguish resource
* @param[out] count Available objects left
*
* @return #SAI_STATUS_NOT_SUPPORTED if the given object type does not support resource accounting.
* Otherwise, return #SAI_STATUS_SUCCESS.
*/
sai_status_t sai_object_type_get_availability(
_In_ sai_object_type_t object_type,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list,
_Out_ uint64_t *count);

/**
* @}
*/
Expand Down
1 change: 1 addition & 0 deletions inc/sainexthopgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ typedef enum _sai_next_hop_group_attr_t
*
* @type sai_next_hop_group_type_t
* @flags MANDATORY_ON_CREATE | CREATE_ONLY
* @isresourcetype true
*/
SAI_NEXT_HOP_GROUP_ATTR_TYPE,

Expand Down
11 changes: 11 additions & 0 deletions inc/sairoute.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ typedef enum _sai_route_entry_attr_t
*/
SAI_ROUTE_ENTRY_ATTR_META_DATA,

/** READ-ONLY */

/**
* @brief Route entry IP address family
*
* @type sai_ip_addr_family_t
* @flags READ_ONLY
* @isresourcetype true
*/
SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY,

/**
* @brief End of attributes
*/
Expand Down
29 changes: 15 additions & 14 deletions meta/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,21 @@ TAB_SIZE = 4
# "Side Effects:". You can put \n's in the value part of an alias to insert
# newlines.

ALIASES += "type =@par Value Type:\n @xmlonly @@type @endxmlonly"
ALIASES += "flags =@par Flags:\n @xmlonly @@flags @endxmlonly"
ALIASES += "objects =@par Allowed object types\n @xmlonly @@objects @endxmlonly"
ALIASES += "allownull =@par Allows NULL object ID\n @xmlonly @@allownull @endxmlonly"
ALIASES += "condition =@par Condition:\n @xmlonly @@condition @endxmlonly"
ALIASES += "validonly =@par Valid only when:\n @xmlonly @@validonly @endxmlonly"
ALIASES += "default =@par Default value:\n @xmlonly @@default @endxmlonly"
ALIASES += "ignore =@par Ignored:\n @xmlonly @@ignore @endxmlonly"
ALIASES += "isvlan =@par IsVlan:\n @xmlonly @@isvlan @endxmlonly"
ALIASES += "count =@par Count:\n @xmlonly @@count @endxmlonly"
ALIASES += "range =@par Range:\n @xmlonly @@range @endxmlonly"
ALIASES += "passparam =@par Pass paramater:\n @xmlonly @@passparam @endxmlonly"
ALIASES += "extraparam =@par Extra paramater:\n @xmlonly @@extraparam @endxmlonly"
ALIASES += "suffix =@par Serialize suffix:\n @xmlonly @@suffix @endxmlonly"
ALIASES += "type =@par Value Type:\n @xmlonly @@type @endxmlonly"
ALIASES += "flags =@par Flags:\n @xmlonly @@flags @endxmlonly"
ALIASES += "objects =@par Allowed object types\n @xmlonly @@objects @endxmlonly"
ALIASES += "allownull =@par Allows NULL object ID\n @xmlonly @@allownull @endxmlonly"
ALIASES += "condition =@par Condition:\n @xmlonly @@condition @endxmlonly"
ALIASES += "validonly =@par Valid only when:\n @xmlonly @@validonly @endxmlonly"
ALIASES += "default =@par Default value:\n @xmlonly @@default @endxmlonly"
ALIASES += "ignore =@par Ignored:\n @xmlonly @@ignore @endxmlonly"
ALIASES += "isvlan =@par IsVlan:\n @xmlonly @@isvlan @endxmlonly"
ALIASES += "count =@par Count:\n @xmlonly @@count @endxmlonly"
ALIASES += "range =@par Range:\n @xmlonly @@range @endxmlonly"
ALIASES += "passparam =@par Pass paramater:\n @xmlonly @@passparam @endxmlonly"
ALIASES += "extraparam =@par Extra paramater:\n @xmlonly @@extraparam @endxmlonly"
ALIASES += "suffix =@par Serialize suffix:\n @xmlonly @@suffix @endxmlonly"
ALIASES += "isresourcetype =@par IsResourceType:\n @xmlonly @@isresourcetype @endxmlonly"

# This tag can be used to specify a number of word-keyword mappings (TCL only).
# A mapping has the form "name=value". For example adding "class=itcl::class"
Expand Down
1 change: 1 addition & 0 deletions meta/aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ingressing
inout
isprint
isvlan
isresourcetype
json
linklocal
lookup
Expand Down
46 changes: 34 additions & 12 deletions meta/parse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@
# TAGS HANDLERS

my %ATTR_TAGS = (
"type" , \&ProcessTagType,
"flags" , \&ProcessTagFlags,
"objects" , \&ProcessTagObjects,
"allownull" , \&ProcessTagAllowNull,
"condition" , \&ProcessTagCondition,
"validonly" , \&ProcessTagCondition, # since validonly uses same format as condition
"default" , \&ProcessTagDefault,
"ignore" , \&ProcessTagIgnore,
"isvlan" , \&ProcessTagIsVlan,
"getsave" , \&ProcessTagGetSave,
"range" , \&ProcessTagRange,
"type" , \&ProcessTagType,
"flags" , \&ProcessTagFlags,
"objects" , \&ProcessTagObjects,
"allownull" , \&ProcessTagAllowNull,
"condition" , \&ProcessTagCondition,
"validonly" , \&ProcessTagCondition, # since validonly uses same format as condition
"default" , \&ProcessTagDefault,
"ignore" , \&ProcessTagIgnore,
"isvlan" , \&ProcessTagIsVlan,
"getsave" , \&ProcessTagGetSave,
"range" , \&ProcessTagRange,
"isresourcetype" , \&ProcessTagIsRecourceType,
);

my %options = ();
Expand Down Expand Up @@ -241,6 +242,16 @@ sub ProcessTagIsVlan
return undef;
}

sub ProcessTagIsRecourceType
{
my ($type, $value, $val) = @_;

return $val if $val =~ /^(true|false)$/i;

LogError "isresourcetype tag value '$val', expected true/false";
return undef;
}

sub ProcessTagRange
{
my ($type, $attrName, $value) = @_;
Expand Down Expand Up @@ -310,7 +321,7 @@ sub ProcessDescription

return if scalar@order == 0;

my $rightOrder = 'type:flags(:objects)?(:allownull)?(:isvlan)?(:default)?(:range)?(:condition|:validonly)?';
my $rightOrder = 'type:flags(:objects)?(:allownull)?(:isvlan)?(:default)?(:range)?(:condition|:validonly)?(:isresourcetype)?';

my $order = join(":",@order);

Expand Down Expand Up @@ -1100,6 +1111,15 @@ sub ProcessAllowNull
return "false";
}

sub ProcessIsResourceType
{
my ($value,$isresourcetype) = @_;

return $isresourcetype if defined $isresourcetype;

return "false";
}

sub ProcessObjects
{
my ($attr, $objects) = @_;
Expand Down Expand Up @@ -1765,6 +1785,7 @@ sub ProcessSingleObjectType
my $cap = ProcessCapability($attr, $meta{type}, $enummetadata);
my $caplen = ProcessCapabilityLen($attr, $meta{type});
my $isextensionattr = ProcessIsExtensionAttr($attr, $meta{type});
my $isresourcetype = ProcessIsResourceType($attr, $meta{isresourcetype});

my $ismandatoryoncreate = ($flags =~ /MANDATORY/) ? "true" : "false";
my $iscreateonly = ($flags =~ /CREATE_ONLY/) ? "true" : "false";
Expand Down Expand Up @@ -1817,6 +1838,7 @@ sub ProcessSingleObjectType
WriteSource ".capability = $cap,";
WriteSource ".capabilitylength = $caplen,";
WriteSource ".isextensionattr = $isextensionattr,";
WriteSource ".isresourcetype = $isresourcetype,";

WriteSource "};";

Expand Down
8 changes: 8 additions & 0 deletions meta/saimetadatatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,14 @@ typedef struct _sai_attr_metadata_t
*/
bool isextensionattr;

/**
* @brief Tells if attribute is a resource type.
*
* If true, attribute is used in getting object type availability
* to distinguish between pools of resources.
*/
bool isresourcetype;

} sai_attr_metadata_t;

/*
Expand Down
5 changes: 5 additions & 0 deletions meta/saisanitycheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,11 @@ void check_non_object_id_object_attrs()

META_ASSERT_NOT_NULL(m);

if (m->isresourcetype)
{
continue;
kcudnik marked this conversation as resolved.
Show resolved Hide resolved
}

switch ((int)m->flags)
{
case SAI_ATTR_FLAGS_MANDATORY_ON_CREATE | SAI_ATTR_FLAGS_CREATE_AND_SET:
Expand Down