#!/bin/bash
#
# description: Set the CPU affinity of the dst_gc_task such that
# it doesn't run on CPUs that are servicing network interrupts.
# This helps to avoid starving dst_gc_task for cycles.  The
# consequence of starving dst_gc_task can be running the system
# out of memory, as seen in BUG155276.
#

# This affinity mask avoids CPU1, which serves network interrupts
# on all Arista hardware platforms, but lets the thread use any
# other CPUs.

KERNEL_VERSION=`uname -r | sed 's/^\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'`
MAJOR_VERSION=`echo $KERNEL_VERSION | sed 's/^\([0-9]*\).*$/\1/'`
MINOR_VERSION=`echo $KERNEL_VERSION | sed 's/^[0-9]*\.\([0-9]*\).*$/\1/'`

if [ "$MAJOR_VERSION" -lt "4" ] || \
    ( [ "$MAJOR_VERSION" -eq "4" ] && [ "$MINOR_VERSION" -lt "13" ] ); then
    AFFINITY=fffffffd
    GC_PID=`pidof dst_gc_task`
    if [ -z "$GC_PID" ]; then
        logger -t -p local4.debug EosGcAffinity "Can't find PID of dst_gc_task"
    else
        taskset -p $AFFINITY $GC_PID | logger -p local4.debug -t EosGcAffinity
    fi
fi
