DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2007-06-13 19:05:35

da_blitz
Member
Registered: 2007-06-13
Posts: 5
Website

Clock drift

I am aware of the clock drift problems but can anyone tell me if its the system clock or the RTC that drifts, from what i could make out on the wiki it seems as if the system clock is the only one to drift (http://dns323.kood.org/howto:reduce_clock_drift)

i belive there is a package for checking drift time of a system clock thats more automated than that, from memeory it also alloms the time to be pulled and sent to the rtc saving alot of work. will post the link when i remeber the name


Embedded Processor Freak
http://www.pocketnix.org

Offline

 

#2 2007-06-13 21:40:06

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: Clock drift

ntp?

Offline

 

#3 2007-06-14 23:42:59

BobE
Member
From: NJ, USA
Registered: 2007-03-24
Posts: 21

Re: Clock drift

The DNS-323 comes with the /usr/sbin/sntp executable which can be run in a daemon mode to keep things synced.  When I was tinkering around with this a few weeks ago (after reading the wiki of course,) I reset the RTC from the system after making sure it was accurate by executing /usr/sbin/rtc -w
Below is my fun_plug and I've attached the script I created for kicking off sntp.  Hope this helps you.

DNS-323 • 2x Western Digital WD5000AAKS 500GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2

Code:

#!/bin/sh
# fun_plug

#
# Start the telnet daemon
#
/mnt/HD_a2/starttelnet.sh

# Adjust Clock 'ticks' to account for drift
/mnt/HD_a2/lnx_bin/busybox3 adjtimex -t 9960

#
# Adjust TimeZone setting
#   USA, East Coast is 5 hours earlier than UTC
#   Daylight Savings Time start/stop is:
#   2nd Sunday in March, 1st Sunday in November
#   2:00AM is default switch time.
#
echo 'EST5EDT,M3.2.0,M11.1.0' > /etc/TZ

# Replace CRON jobs
crontab -r
echo '*/10 * * * * /usr/sbin/getdhcp&' > /var/spool/cron/crontabs/root
crontab /var/spool/cron/crontabs/root

# Kick off the network time daemon
/mnt/HD_a2/start_sntp.sh

• DNS-323 A1 | FW1.09 | 2x WD20EVDS AV-GP 2TB SATA 3.0Gb/s 7200RPM, 32MB | RAID1 | ext3 | ffp 0.5,  Samba 3.4.6-1

• NSA-220+ | FW3.23 | 2x WD15EADS “Green” 1.5TB SATA 3.0Gb/s 7200RPM, 32MB | RAID1 | ext3 | External USB: Kingston DT1 2GB Flash Drive ( ffp 0.5 )

Offline

 

#4 2007-06-16 10:40:46

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: Clock drift

For what I could tell (testing on fw v1.02 USA)
the system clock drifts in one direction and the rtc clock drifts in the other direction.
the rtc drifts much slower than the system.
The way D-link handles this clock drift issue (with native firmware) is with a nightly root cron task.
This cron task sets the 'quickly drifting' system time to the 'slowly drifting' rtc time at 2:30am. 

I've attached a plot of the hourly time with the default D-link time management enabled (max drift ~5 min)

Last edited by mig (2007-06-16 10:45:35)


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#5 2007-06-16 10:43:50

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: Clock drift

I manage the time drift on my DNS-323 by:

1  first use the 'adjtimex -t 9960' command
2  then execute a script 'ntp_sync.sh'
           which uses sntp to sync the DNS-323 system time with my in-house time server
           and then sync the DNS-323 rtc to the DNS-323 system time
3   then remove any cron tasks with either 'daylight' or 'rtc' in the command
4   then install a new cron task to run the 'ntp_sync.sh' at 2:05am every day.

    the above logic is implemented in the fun_plug and associated initialization scripts.

This attachment is a plot of hourly time with my time management enabled. (max drift ~5 seconds)

Last edited by mig (2007-06-18 03:53:07)


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#6 2007-08-05 16:39:30

mre
Member
From: LO in Germany
Registered: 2007-08-05
Posts: 21

Re: Clock drift

I've changed a little bit the startup script from fonz (timezone.sh) and combined the ideas already submitted, so that the time is set every hour from ntp and written daily to the RTC, some little changes to the crontab to reflect this and to stop the rtc and daylight tasks.

@fonz: maybe you can check it and implement it in your funplug (I love it, thanks a lot).

btw: How can I make an attachement?

Offline

 

#7 2007-08-06 12:08:38

hennemtk
Member
From: Germany
Registered: 2007-07-16
Posts: 23

Re: Clock drift

mre wrote:

I've changed a little bit the startup script from fonz (timezone.sh) and combined the ideas already submitted, so that the time is set every hour from ntp and written daily to the RTC, some little changes to the crontab to reflect this and to stop the rtc and daylight tasks.

@fonz: maybe you can check it and implement it in your funplug (I love it, thanks a lot).

btw: How can I make an attachement?

Sounds very interesting to me!

Attachment: When you write a meesage to this forum there is an extra field under the message field named "attachment" and a button right next to it to browse and select an attachment. Should be straight forward.

Regards
Thomas

Offline

 

#8 2007-08-06 14:30:27

mre
Member
From: LO in Germany
Registered: 2007-08-05
Posts: 21

Re: Clock drift

@hennemtk Thanks, there is a difference between Post and Quickpost (with and w/o attachment wink ). Nice to know. So 'll take Post for attachments.

Would be fine, if you could monitor the sntp process over one or 2 days or so (ps -A should be enough) to see if it's still working. You can make timezone.sh executable, so it becames autostartable (see fonz funplug readme for details).

Slightly modified the script, so please use the new timezone.sh.

Last edited by mre (2007-08-06 16:39:09)

Offline

 

#9 2007-10-13 23:23:07

cybermike
Member
Registered: 2007-09-09
Posts: 18

Re: Clock drift

mre wrote:

Slightly modified the script, so please use the new timezone.sh.

So the only change is the replace the timezone.sh i the start directroy and chmod 777 timezone.sh, right? I guess i did it right because there is now a sntp.log and fun_plug.log tells me that timezon.sh was started.

Great, thanks :-)

Michael

Offline

 

#10 2007-10-14 01:53:37

mre
Member
From: LO in Germany
Registered: 2007-08-05
Posts: 21

Re: Clock drift

Better change the fun_plug file directly an forget the timezone.sh. The process dies from time to time and so you have the drift again. My NAS runs for 24/7 and I don't like to check if the process s still running. So here are my changes for fun_plug, insert it and all is fine wink

#SET correct Timezone on every boot ** BEGIN **
#SET the TZ for Berlin

TZ=CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
export TZ

#Adjust Clock 'ticks' to account for drift or RTC time
${BINDIR}/busybox adjtimex -t 9960

# Replace CRON jobs and append sntp job for executing every hour at x.03 o'clock
# Write RTC time from system time every day at 2.32 a.m.

crontab -l |sed -e '/rtc\ -c/d' -e '/daylight/d' -e 's/rtc\ -s/rtc\ -w/g' -e '$a03 * * * * /usr/sbin/sntp -r -P no de.pool.ntp.org &' |crontab -
# executing the time protocol every boot to set correct time during boot up process
/usr/sbin/sntp -r -P no de.pool.ntp.org 1>${LOGFILE} 2>&1 &

# #SET correct Timezone on every boot ** END **

Salve Mike

Offline

 

#11 2007-10-14 09:38:09

cybermike
Member
Registered: 2007-09-09
Posts: 18

Re: Clock drift

mre wrote:

Better change the fun_plug file directly an forget the timezone.sh. The process dies from time to time and so you have the drift again. My NAS runs for 24/7 and I don't like to check if the process s still running. So here are my changes for fun_plug, insert it and all is fine.

Just a stupid question fom a Linux Dummy like me: You mean to insert the lines of code from Your previous post in the fun_plug file and remove the timezone.sh file, right? Or is the timezone.sh still required. How can i see that it works, i just tried it and there is no entry in the fun_plug.log.

Does this keep the time correctly or does it just set the correct time at startup time?

Here is my complete fun_plug (using a CH3SNAS), is that all correct?

My fun_plug wrote:

#!/bin/sh

VOL1=/mnt/HD_a2
VOL2=/mnt/HD_b2
FUNPLUGTAR=${VOL1}/fun_plug.tar
FUNPLUGDIR=${VOL1}/fun_plug.d
ETCDIR=${FUNPLUGDIR}/etc
BINDIR=${FUNPLUGDIR}/bin
SBINDIR=${FUNPLUGDIR}/bin
LIBDIR=${FUNPLUGDIR}/lib
LOGDIR=${FUNPLUGDIR}/log
LOGFILE=${LOGDIR}/fun_plug.log
PATH=${BINDIR}:${PATH}
LD_LIBRARY_PATH=${LIBDIR}

export VOL1
export VOL2
export FUNPLUGDIR
export ETCDIR
export BINDIR
export LIBDIR
export LOGDIR
export LOGFILE
export PATH
export LD_LIBRARY_PATH

umask 022

mkdir -p ${FUNPLUGDIR} ${LOGDIR}
echo "**** fun_plug script for DNS-323 (2007-07-22 tp@fonz.de) ****" >>${LOGFILE}
date >>${LOGFILE}

if [ -r "${FUNPLUGTAR}" ]; then
    echo "* Extracting ${FUNPLUGTAR}..." >>${LOGFILE}
    /bin/tar -xv -f ${FUNPLUGTAR} -C ${FUNPLUGDIR} 1>>${LOGFILE} 2>&1
    echo "* Deleting ${FUNPLUGTAR}..." >>${LOGFILE}
    rm -f ${FUNPLUGTAR}
fi

# suid busybox
if [ -e ${BINDIR}/busybox ]; then
    chown root.root ${BINDIR}/busybox
    chmod 0755 ${BINDIR}/busybox
    chmod u+s ${BINDIR}/busybox
fi

echo "${LIBDIR}" >>/etc/ld.so.conf
ldconfig

if [ -d "${FUNPLUGDIR}/start" ]; then
    for fun_plug_script in ${FUNPLUGDIR}/start/*.sh; do
        if [ -x "${fun_plug_script}" ]; then
            echo "* Running ${fun_plug_script} start ..." >>${LOGFILE}
            ${fun_plug_script} start 1>>${LOGFILE} 2>&1
        else
            echo "* ${fun_plug_script} not executable..." >>${LOGFILE}
        fi
    done
else
    echo "* ${FUNPLUGDIR}/start: Directory not found"
fi

echo "* Done" >>${LOGFILE}

#SET correct Timezone on every boot ** BEGIN **
#SET the TZ for Berlin

TZ=CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
export TZ

#Adjust Clock 'ticks' to account for drift or RTC time
${BINDIR}/busybox adjtimex -t 9960

# Replace CRON jobs and append sntp job for executing every hour at x.03 o'clock
# Write RTC time from system time every day at 2.32 a.m.

crontab -l |sed -e '/rtc\ -c/d' -e '/daylight/d' -e 's/rtc\ -s/rtc\ -w/g' -e '$a03 * * * * /usr/sbin/sntp -r -P no de.pool.ntp.org &' |crontab -
# executing the time protocol every boot to set correct time during boot up process
/usr/sbin/sntp -r -P no de.pool.ntp.org 1>${LOGFILE} 2>&1 &

# #SET correct Timezone on every boot ** END **

# restart samba
/mnt/HD_a2/startsmb.sh

# firefly itunes server
/mnt/HD_a2/startfirefly.sh

# twonkymedia upnp server
/mnt/HD_a2/starttwonky.sh

AHHH, the line "Write RTC time from system time every day at 2.32 a.m" explains it. It corrects the time every deay at 2.32, not permanently or every 10 minutes :-)


regards
Michael

Last edited by cybermike (2007-10-14 09:52:37)

Offline

 

#12 2007-10-17 13:02:57

mre
Member
From: LO in Germany
Registered: 2007-08-05
Posts: 21

Re: Clock drift

Not really correct,

#Replace CRON jobs and append sntp job for executing every hour at x.03 o'clock
So every hour at 3 minutes after full clock the time is set with the sntp command. So you have the correct time with minimal drift. And the process doesn't run permanently.

# Write RTC time from system time every day at 2.32 a.m.
This syncs both times on the NAS. (The system and the RTC clock, have a look at the wiki to understand the differences).

BTW: You can telnet to the NAS and execute "crontab -l" to see the new cronjobs.

Offline

 

#13 2009-02-19 00:33:07

cryoglobe
Member
Registered: 2007-10-24
Posts: 7

Re: Clock drift

Hello

I have a small question about my dns-323 , it's always 20 minutes in advance to my normal time ...
If I change the time , it is of course rechanged by night ( by the RTC's command in the crontab )

What's the simpliest way to make this at the correct time ... ( so 20 minutes before ) ?
It's really enoying as my Dns-323 is running squeezecenter and is the place where my squeezebox takes the time it shows when not beeing playing music !

-- update --

For information
Here is the content of the crontab :

32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
59 1 * * * /usr/sbin/daylight &


Thanks for the answers.

Last edited by cryoglobe (2009-02-22 10:11:17)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB