sonic-buildimage/device/celestica/x86_64-cel_seastone-r0/sonic_platform
Ikki Zhu 9fcbd5ed1d
fix possible cpld race access issue (#15371)
Why I did it
fix possible cpld race read issue between watchdog and reboot cause
process

How I did it
Use fcntl.flock to limit parallel access to cpld sys file

How to verify it
It can be simulated and verified with following python script

``` python3
import fcntl
import signal
import threading

exit_flag = False

def get_cpld_reg_value(getreg_path, register):
    file = open(getreg_path, 'w+')
    # Acquire an exclusive lock on the file
    fcntl.flock(file, fcntl.LOCK_EX)

    try:
        file.write(register + '\n')
        file.flush()

        # Seek to the beginning of the file
        file.seek(0)

        # Read the content of the file
        result = file.readline().strip()
    finally:
        # Release the lock and close the file
        fcntl.flock(file, fcntl.LOCK_UN)
        file.close()

    return result

def cpld_read(thread_num, cpld_reg, expect_val):
    while not exit_flag:
        val
= get_cpld_reg_value("/sys/devices/platform/dx010_cpld/getreg",
cpld_reg)
        #print(f"Thread {thread_num}: get cpld reg {cpld_reg}, value
{val}")
        if val != expect_val:
            print(f"Thread {thread_num}: get cpld reg {cpld_reg}, value
{val}, expect_val {expect_val}")

def signal_handler(sig, frame):
    global exit_flag
    print("Ctrl+C detected. Quitting...")
    exit_flag = True

if __name__ == '__main__':
    # Register the signal handler for Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    t1 = threading.Thread(target=cpld_read, args=(1, '0x103', '0x11',))
    t2 = threading.Thread(target=cpld_read, args=(2, '0x141', '0x00',))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
```
2023-06-07 11:29:18 -07:00
..
__init__.py [sonic-utilities] Update submodule; Build and install as a Python 3 wheel (#5926) 2020-11-25 10:28:36 -08:00
chassis.py [Seastone] DX010 platform switch to sfp-refactor based sfp impl (#13972) 2023-03-27 10:17:21 -07:00
component.py fix possible cpld race access issue (#15371) 2023-06-07 11:29:18 -07:00
eeprom.py [DX010 platform] fix dx010 platform testcase issues (#13595) 2023-02-09 19:07:13 -08:00
event.py [device/celestica]: Add xcvrd event support for Seastone-DX010 (#5896) 2020-12-14 10:22:56 -08:00
fan_drawer.py [Celestica DX010] fix fan drawer and watchdog platform testcase issues (#13426) 2023-02-06 09:27:46 -08:00
fan.py Seastone: fix platform fan psu and temperature issues (#12567) 2022-12-05 09:44:55 -08:00
helper.py fix possible cpld race access issue (#15371) 2023-06-07 11:29:18 -07:00
platform.py [sonic-utilities] Update submodule; Build and install as a Python 3 wheel (#5926) 2020-11-25 10:28:36 -08:00
psu.py [Celestica Seastone] fix multi sonic platform issues (#13356) 2023-01-18 16:27:48 -08:00
sfp_optoe.py [Seastone] DX010 platform switch to sfp-refactor based sfp impl (#13972) 2023-03-27 10:17:21 -07:00
sfp.py [Seastone] fix dx010 qsfp eeprom data write issue (#13930) 2023-03-01 14:35:53 +08:00
thermal_actions.py [device/celestica] Mitigation for command injection vulnerability (#11740) 2022-12-09 10:30:20 -05:00
thermal_conditions.py [device/celestica]: Add thermalctld support on DX010 platform APIs (#6089) 2021-01-15 10:20:47 -08:00
thermal_infos.py [device/celestica]: Add thermalctld support on DX010 platform APIs (#6089) 2021-01-15 10:20:47 -08:00
thermal_manager.py [device/celestica] Mitigation for command injection vulnerability (#11740) 2022-12-09 10:30:20 -05:00
thermal.py [device/celestica]:Fix failed test case of Seastone snmp (#11430) 2022-07-27 12:14:13 +08:00
watchdog.py [Celestica DX010] fix fan drawer and watchdog platform testcase issues (#13426) 2023-02-06 09:27:46 -08:00