Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,6 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
for (string port_name : port_names)
{
Port port;
bool portUpdated = false;
SWSS_LOG_DEBUG("processing port:%s", port_name.c_str());
if (!gPortsOrch->getPort(port_name, port))
{
Expand All @@ -1064,12 +1063,6 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
SWSS_LOG_ERROR("Invalid pg index specified:%zd", ind);
return task_process_status::task_invalid_entry;
}
if (port.m_priority_group_lock[ind])
{
SWSS_LOG_WARN("Priority group %zd on port %s is locked, pending profile 0x%" PRIx64 " until unlocked", ind, port_name.c_str(), sai_buffer_profile);
portUpdated = true;
port.m_priority_group_pending_profile[ind] = sai_buffer_profile;
}
else
{
if (need_update_sai)
Expand All @@ -1090,10 +1083,6 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
}
}
}
if (portUpdated)
{
gPortsOrch->setPort(port_name, port);
}
}

if (m_ready_list.find(key) != m_ready_list.end())
Expand Down
119 changes: 29 additions & 90 deletions orchagent/pfcactionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port,
return;
}

setPriorityGroupAndQueueLockFlag(portInstance, true);
setQueueLockFlag(portInstance, true);

sai_attribute_t attr;
attr.id = SAI_QUEUE_ATTR_BUFFER_PROFILE_ID;
Expand All @@ -583,7 +583,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port,
sai_object_id_t oldQueueProfileId = attr.value.oid;

attr.id = SAI_QUEUE_ATTR_BUFFER_PROFILE_ID;
attr.value.oid = ZeroBufferProfile::getZeroBufferProfile(false);
attr.value.oid = ZeroBufferProfile::getZeroBufferProfile();

// Set our zero buffer profile
status = sai_queue_api->set_queue_attribute(queue, &attr);
Expand All @@ -595,35 +595,6 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port,

// Save original buffer profile
m_originalQueueBufferProfile = oldQueueProfileId;

// Get PG
sai_object_id_t pg = portInstance.m_priority_group_ids[static_cast <size_t> (queueId)];

attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE;

// Get PG's buffer profile
status = sai_buffer_api->get_ingress_priority_group_attribute(pg, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get buffer profile ID on PG 0x%" PRIx64 ": %d", pg, status);
return;
}

// Set zero profile to PG
sai_object_id_t oldPgProfileId = attr.value.oid;

attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE;
attr.value.oid = ZeroBufferProfile::getZeroBufferProfile(true);

status = sai_buffer_api->set_ingress_priority_group_attribute(pg, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set buffer profile ID on pg 0x%" PRIx64 ": %d", pg, status);
return;
}

// Save original buffer profile
m_originalPgBufferProfile = oldPgProfileId;
}

PfcWdZeroBufferHandler::~PfcWdZeroBufferHandler(void)
Expand All @@ -649,41 +620,12 @@ PfcWdZeroBufferHandler::~PfcWdZeroBufferHandler(void)
return;
}

auto idx = size_t(getQueueId());
sai_object_id_t pg = portInstance.m_priority_group_ids[idx];
sai_object_id_t pending_profile_id = portInstance.m_priority_group_pending_profile[idx];

attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE;

if (pending_profile_id != SAI_NULL_OBJECT_ID)
{
attr.value.oid = pending_profile_id;
SWSS_LOG_NOTICE("Priority group %zd on port %s has been restored to pending profile 0x%" PRIx64,
idx, portInstance.m_alias.c_str(), pending_profile_id);
portInstance.m_priority_group_pending_profile[idx] = SAI_NULL_OBJECT_ID;
}
else
{
attr.value.oid = m_originalPgBufferProfile;
SWSS_LOG_NOTICE("Priority group %zd on port %s has been restored to original profile 0x%" PRIx64,
idx, portInstance.m_alias.c_str(), m_originalPgBufferProfile);
}

// Set our zero buffer profile
status = sai_buffer_api->set_ingress_priority_group_attribute(pg, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%" PRIx64 ": %d", getQueue(), status);
return;
}

setPriorityGroupAndQueueLockFlag(portInstance, false);
setQueueLockFlag(portInstance, false);
}

void PfcWdZeroBufferHandler::setPriorityGroupAndQueueLockFlag(Port& port, bool isLocked) const
void PfcWdZeroBufferHandler::setQueueLockFlag(Port& port, bool isLocked) const
{
// set lock bits on PG and queue
port.m_priority_group_lock[static_cast<size_t>(getQueueId())] = isLocked;
// set lock bits on queue
for (size_t i = 0; i < port.m_queue_ids.size(); ++i)
{
if (port.m_queue_ids[i] == getQueue())
Expand All @@ -703,9 +645,8 @@ PfcWdZeroBufferHandler::ZeroBufferProfile::~ZeroBufferProfile(void)
{
SWSS_LOG_ENTER();

// Destroy ingress and egress profiles and pools
destroyZeroBufferProfile(true);
destroyZeroBufferProfile(false);
// Destroy egress profiles and pools
destroyZeroBufferProfile();
}

PfcWdZeroBufferHandler::ZeroBufferProfile &PfcWdZeroBufferHandler::ZeroBufferProfile::getInstance(void)
Expand All @@ -717,46 +658,45 @@ PfcWdZeroBufferHandler::ZeroBufferProfile &PfcWdZeroBufferHandler::ZeroBufferPro
return instance;
}

sai_object_id_t& PfcWdZeroBufferHandler::ZeroBufferProfile::getPool(bool ingress)
sai_object_id_t& PfcWdZeroBufferHandler::ZeroBufferProfile::getPool()
{
// If there is a cached zero buffer pool, just use it
// else fetch zero buffer pool from buffer orch
// If there is one, use it and increase the reference number.
// otherwise, just return NULL OID
// PfcWdZeroBufferHandler will create it later and notify buffer orch later
auto &poolId = ingress ? m_zeroIngressBufferPool : m_zeroEgressBufferPool;
if (poolId == SAI_NULL_OBJECT_ID)
if (m_zeroEgressBufferPool == SAI_NULL_OBJECT_ID)
{
poolId = gBufferOrch->getZeroBufferPool(ingress);
if (poolId != SAI_NULL_OBJECT_ID)
m_zeroEgressBufferPool = gBufferOrch->getZeroBufferPool(false);
if (m_zeroEgressBufferPool != SAI_NULL_OBJECT_ID)
{
gBufferOrch->lockZeroBufferPool(ingress);
gBufferOrch->lockZeroBufferPool(false);
}
}
return poolId;
return m_zeroEgressBufferPool;
}

sai_object_id_t PfcWdZeroBufferHandler::ZeroBufferProfile::getZeroBufferProfile(bool ingress)
sai_object_id_t PfcWdZeroBufferHandler::ZeroBufferProfile::getZeroBufferProfile()
{
SWSS_LOG_ENTER();

if (getInstance().getProfile(ingress) == SAI_NULL_OBJECT_ID)
if (getInstance().getProfile() == SAI_NULL_OBJECT_ID)
{
getInstance().createZeroBufferProfile(ingress);
getInstance().createZeroBufferProfile();
}

return getInstance().getProfile(ingress);
return getInstance().getProfile();
}

void PfcWdZeroBufferHandler::ZeroBufferProfile::createZeroBufferProfile(bool ingress)
void PfcWdZeroBufferHandler::ZeroBufferProfile::createZeroBufferProfile()
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
vector<sai_attribute_t> attribs;
sai_status_t status;

auto &poolId = getPool(ingress);
auto &poolId = getPool();

if (SAI_NULL_OBJECT_ID == poolId)
{
Expand All @@ -766,7 +706,7 @@ void PfcWdZeroBufferHandler::ZeroBufferProfile::createZeroBufferProfile(bool ing
attribs.push_back(attr);

attr.id = SAI_BUFFER_POOL_ATTR_TYPE;
attr.value.u32 = ingress ? SAI_BUFFER_POOL_TYPE_INGRESS : SAI_BUFFER_POOL_TYPE_EGRESS;
attr.value.u32 = SAI_BUFFER_POOL_TYPE_EGRESS;
attribs.push_back(attr);

attr.id = SAI_BUFFER_POOL_ATTR_THRESHOLD_MODE;
Expand All @@ -785,15 +725,15 @@ void PfcWdZeroBufferHandler::ZeroBufferProfile::createZeroBufferProfile(bool ing
}

// Pass the ownership to BufferOrch
gBufferOrch->setZeroBufferPool(ingress, poolId);
gBufferOrch->lockZeroBufferPool(ingress);
gBufferOrch->setZeroBufferPool(false, poolId);
gBufferOrch->lockZeroBufferPool(false);
}

// Create zero profile
attribs.clear();

attr.id = SAI_BUFFER_PROFILE_ATTR_POOL_ID;
attr.value.oid = getPool(ingress);
attr.value.oid = getPool();
attribs.push_back(attr);

attr.id = SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE;
Expand All @@ -809,7 +749,7 @@ void PfcWdZeroBufferHandler::ZeroBufferProfile::createZeroBufferProfile(bool ing
attribs.push_back(attr);

status = sai_buffer_api->create_buffer_profile(
&getProfile(ingress),
&getProfile(),
gSwitchId,
static_cast<uint32_t>(attribs.size()),
attribs.data());
Expand All @@ -820,23 +760,22 @@ void PfcWdZeroBufferHandler::ZeroBufferProfile::createZeroBufferProfile(bool ing
}
}

void PfcWdZeroBufferHandler::ZeroBufferProfile::destroyZeroBufferProfile(bool ingress)
void PfcWdZeroBufferHandler::ZeroBufferProfile::destroyZeroBufferProfile()
{
SWSS_LOG_ENTER();

if (getProfile(ingress) != SAI_NULL_OBJECT_ID)
if (getProfile() != SAI_NULL_OBJECT_ID)
{
sai_status_t status = sai_buffer_api->remove_buffer_profile(getProfile(ingress));
sai_status_t status = sai_buffer_api->remove_buffer_profile(getProfile());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove static zero buffer profile for PFC WD: %d", status);
return;
}
}

auto &pool = ingress ? m_zeroIngressBufferPool : m_zeroEgressBufferPool;
if (pool != SAI_NULL_OBJECT_ID)
if (m_zeroEgressBufferPool != SAI_NULL_OBJECT_ID)
{
gBufferOrch->unlockZeroBufferPool(ingress);
gBufferOrch->unlockZeroBufferPool(false);
}
}
23 changes: 10 additions & 13 deletions orchagent/pfcactionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,39 +125,36 @@ class PfcWdZeroBufferHandler: public PfcWdLossyHandler

private:
/*
* Sets lock bits on port's priority group and queue
* to protect them from being changed by other Orch's
*/
void setPriorityGroupAndQueueLockFlag(Port& port, bool isLocked) const;
* Sets lock bits on port's queue
* to protect it from being changed by other Orch's
*/
void setQueueLockFlag(Port& port, bool isLocked) const;

// Singletone class for keeping shared data - zero buffer profiles
class ZeroBufferProfile
{
public:
~ZeroBufferProfile(void);
static sai_object_id_t getZeroBufferProfile(bool ingress);
static sai_object_id_t getZeroBufferProfile();

private:
ZeroBufferProfile(void);
static ZeroBufferProfile &getInstance(void);
void createZeroBufferProfile(bool ingress);
void destroyZeroBufferProfile(bool ingress);
void createZeroBufferProfile();
void destroyZeroBufferProfile();

sai_object_id_t& getProfile(bool ingress)
sai_object_id_t& getProfile()
{
return ingress ? m_zeroIngressBufferProfile : m_zeroEgressBufferProfile;
return m_zeroEgressBufferProfile;
}

sai_object_id_t& getPool(bool ingress);
sai_object_id_t& getPool();

sai_object_id_t m_zeroIngressBufferPool = SAI_NULL_OBJECT_ID;
sai_object_id_t m_zeroEgressBufferPool = SAI_NULL_OBJECT_ID;
sai_object_id_t m_zeroIngressBufferProfile = SAI_NULL_OBJECT_ID;
sai_object_id_t m_zeroEgressBufferProfile = SAI_NULL_OBJECT_ID;
};

sai_object_id_t m_originalQueueBufferProfile = SAI_NULL_OBJECT_ID;
sai_object_id_t m_originalPgBufferProfile = SAI_NULL_OBJECT_ID;
};

// PFC queue that implements drop action by draining queue via SAI
Expand Down
8 changes: 3 additions & 5 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,13 @@ class Port
bool m_mpls = false;

/*
* Following two bit vectors are used to lock
* the PG/queue from being changed in BufferOrch.
* Following bit vector is used to lock
* the queue from being changed in BufferOrch.
* The use case scenario is when PfcWdZeroBufferHandler
* sets zero buffer profile it should protect PG/queue
* sets zero buffer profile it should protect queue
* from being overwritten in BufferOrch.
*/
std::vector<bool> m_queue_lock;
std::vector<bool> m_priority_group_lock;
std::vector<sai_object_id_t> m_priority_group_pending_profile;

std::unordered_set<sai_object_id_t> m_ingress_acl_tables_uset;
std::unordered_set<sai_object_id_t> m_egress_acl_tables_uset;
Expand Down
2 changes: 0 additions & 2 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4135,8 +4135,6 @@ void PortsOrch::initializePriorityGroups(Port &port)
SWSS_LOG_INFO("Get %d priority groups for port %s", attr.value.u32, port.m_alias.c_str());

port.m_priority_group_ids.resize(attr.value.u32);
port.m_priority_group_lock.resize(attr.value.u32);
port.m_priority_group_pending_profile.resize(attr.value.u32);

if (attr.value.u32 == 0)
{
Expand Down
Loading