Unable to stop watchdog jetson TX2

Hi,I am setting watchdog timeout value after that that system is rebooting.

so my use case is after setting watchdog timout i am stopping it, but not able to stop.

I am getting below error ::

watchdog: watchdog0: watchdog did not stop!

can you please help what could be the issue.

You might find this of use:
https://forums.developer.nvidia.com/t/unable-to-stop-watchdog/127003/5

There might also be some useful information here:
https://devtalk.nvidia.com/default/topic/1046526/jetson-tx2/there-seems-to-be-something-wrong-with-t18x_a57_enter_state-function-/post/5311392/#5311392

1 Like

for Tx2 with SDK 32.4.3, can you suggest changes

Sorry, I have no suggestions for any particular case. However, you might want to post the exact enable steps, and exact steps for what you’ve tried to use to stop the timer (an ability to reproduce this in exactly the same way would help with debugging).

wdt_fd = /dev/watchdog0
=========this function is for stoppong the wdt============
int stop_wdt_ping_cmd(U32 argc, char **argv, contextInfo_t *c)
{
int ret;

        printf("..........stop_wdt_ping_cmd..........\n");
if(wdt_fd <= 0) {
    printf("WDT device is not opened\n");
    return FAILURE;
}
    wdt_thread_running =1;
if(wdt_thread_running){
    ret = pthread_cancel(wdt_thread);
    if(ret == 0) {
        wdt_thread_running = 0;
        printf("WDT ping thread has been terminated\n");
    } else {
        printf("Failed to cancel the WDT ping thread\n");
    }
} else {
    printf("Thread not running:::::WDT ping thread has been already terminated\n");
}
wdt_close(&wdt_fd);
    SET_TIME_OUT_CALL = 0;
return 0;

}

int wdt_ping_cmd (U32 argc, char **argv, contextInfo_t *c)
{
int ret=0;
char cmd[8] = “WDT PING”;

if(wdt_fd > 0) {
    printf("WDT Device is already opened\n");
}
else {
    ret =wdt_open(&wdt_fd);
    if(ret < 0)
        return FAILURE;
}
if(SET_TIME_OUT_CALL == 1) {
    if((strcmp(argv[2],"1") ==0)) {
        if(wdt_thread_running == 1) {
            printf(" WDT is already getting ping\n");
            return SUCCESS;
        }
        ret = pthread_create(&wdt_thread, NULL, wdt_func, (void*) cmd);
        if(ret) {
            fprintf(stderr,": WDT_ERR in pthread create with %d\n",ret);
            return FAILURE;
        }
            printf(" WDT Ping Started\n");
    }else{
        if((strcmp(argv[2],"0") ==0))       {
            ret =wdt_keepalive(&wdt_fd);
            if(ret < 0 )
    return FAILURE;
        }
    }
}else {
    printf("Time out not SET from APP--> pinging for default time \n");
    if(wdt_thread_running == 0) {
        if((strcmp(argv[2],"1") ==0))   {
            ret = pthread_create(&wdt_thread, NULL, wdt_func, (void*) cmd);
            if(ret) {
                fprintf(stderr,"Error - pthread_create() return code: %d\n",ret);
                return FAILURE;
            }
            printf(" WDT Ping Started\n");
        }else if((strcmp(argv[2],"0") ==0)){
                ret =wdt_keepalive(&wdt_fd);
                if(ret <0 )
                    return FAILURE;
            }
    }else if(wdt_thread_running == 1) {
        printf(" WDT is already getting ping for default time out\n");
        return SUCCESS;
    }
}
return SUCCESS;

}

void *wdt_func(void *msg)
{
wdt_thread_running = 1;
while(1) {
sleep(2);
wdt_keepalive(&wdt_fd);
}
}
=============for setting wdt==============

int wdt_set_cmd (U32 argc, char **argv, contextInfo_t *c)
{
int timeout = 0,ret=0;
timeout =atoi(argv[2]); /*Time in seconds */

        printf(".............wdt_set_cmd..........\n");
if(timeout < WDT_MIN_SETTIME || timeout > WDT_MAX_SETTIME){
    printf("WDT:Provide the valid timeout\n Range is 20 - 65535 seconds \n");
    return FAILURE;
}

if(SET_TIME_OUT_CALL == 0) {
    ret = wdt_open(&wdt_fd);
    if(ret < 0)
        return FAILURE;
    ret=set_wdt_timeout(&wdt_fd,timeout);
    if(ret<0){
        return FAILURE;
    }else{
        printf("Watchdog timeout set success \n");
        SET_TIME_OUT_CALL = 1;
        return SUCCESS;
    }
}else{
    printf("Operation SET TIME OUT not supported-->WDT  Already Set\n");
    return SUCCESS;
}

}

int set_wdt_timeout(int *wdt_fd,int timeout)
{
wdt_print(LOG_ERR “%s Enter…\n”, func);
if(*wdt_fd < 0) {
wdt_print(LOG_ERR “Watchdog device not opened\n”);
return WDT_FAILURE;
}

if(timeout >= WDT_MIN_SETTIME && timeout <= WDT_MAX_SETTIME){
    int ret;
    /* Note the value should be within [20, 1000] */
    ret = ioctl(*wdt_fd, WDIOC_SETTIMEOUT, &timeout);
    if(ret) {
        wdt_print(LOG_ERR "Set watchdog timeout value failed!\n");
        return WDT_FAILURE * errno;
    }
}else{
    wdt_print(LOG_ERR "Provide the valid timeout\n Range is 20 - 65535 seconds \n");
    return WDT_FAILURE;
}
    wdt_print(LOG_ERR "%s Exit...\n", __func__);
return WDT_SUCCESS;

}

int wdt_keepalive(int *wdt_fd)
{
int ret=0;

    wdt_print(LOG_ERR "%s Enter...\n", __func__);
if(*wdt_fd < 0) {
    wdt_print(LOG_ERR "Watchdog device not opened\n");
    return WDT_FAILURE;
}
ret = ioctl(*wdt_fd, WDIOC_KEEPALIVE, NULL);
if(ret) {
    wdt_print(LOG_ERR "Kick watchdog failed!\n");
    return WDT_FAILURE;
}
    wdt_print(LOG_ERR "%s Exit...\n", __func__);
return WDT_SUCCESS;

}

can you check this

I did not actually try building this, but would it be possible to upload the actual C files? If the forum does not like the suffix, then you could just rename the files with a “.c.txt” file name suffix.

I also did not look closely at the pthread content, but it is possible for a thread to be in a state where pthread_cancel() does not cause a thread to actually cancel. The init function of the thread create is “wdt_func()”. If you add a print statement which shows up for wdt_func() upon exit, then you’d know if the cancel actually ended the thread.

i am getting below kernel message [ 1038.167727] watchdog: watchdog0: watchdog did not stop! also it is showing thread has been terminated

after setting watchdog time out when i am running below command i am getting watchdog didnot stop error

root@localhost:/home/ubuntu# echo ‘V’ > /dev/watchdog
[ 182.230179] watchdog: watchdog0: watchdog did not stop!

In the other URLs I mentioned there was some discussion of the timer, and I believe possible patches were discussed. I do not know what was ultimately figured out from that, but it does seem that some watchdog timer changes have occurred over time (from the kernel people, not NVIDIA), and I am not sure what differences need to be accounted for. I think someone else will have to answer that since the other threads did not have what you need.

The closest I found to this was a kernel.org thread, but the thread did not say enough to help:
https://bugzilla.kernel.org/show_bug.cgi?id=189971
(most threads were about the timer during intentional shutdown, and not about the timer continuing after telling the timer to stop)

Have modify the …/kernel/kernel-4.9/arch/arm64/configs/tegra_defconfig to remove the CONFIG_WATCHDOG_NOWAYOUT=y for permission to disable the watchdog by sysfs.