Friday, December 6, 2019

linux kernel scheduling class



ps -deo pid,cls,cmd | grep -e RR -e FF


       cls       CLS    scheduling class of the process. (alias policy, class).
                        Field's possible values are:
                        -   not reported
                        TS  SCHED_OTHER
                        FF  SCHED_FIFO
                        RR  SCHED_RR
                        B   SCHED_BATCH
                        ISO SCHED_ISO
                        IDL SCHED_IDLE
                        ?   unknown value

root@:/proc/sys/kernel# cat sched_rt_period_us
1000000
root@:/proc/sys/kernel# cat sched_rt_runtime_us
950000

Friday, November 22, 2019

kernel abort

arch/arm/mm/fsr-2level.c , fsr-3level.c

static struct fsr_info fsr_info[] = {
/*
* The following are the standard ARMv3 and ARMv4 aborts.  ARMv5
* defines these to be "precise" aborts.
*/
{ do_bad, SIGSEGV, 0, "vector exception"    },
{ do_bad, SIGBUS, BUS_ADRALN, "alignment exception"    },
{ do_bad, SIGKILL, 0, "terminal exception"    },
{ do_bad, SIGBUS, BUS_ADRALN, "alignment exception"    },
{ do_bad, SIGBUS, 0, "external abort on linefetch"    },
{ do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault"    },
{ do_bad, SIGBUS, 0, "external abort on linefetch"    },
{ do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault"    },
{ do_bad, SIGBUS, 0, "external abort on non-linefetch"  },
{ do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault"    },
{ do_bad, SIGBUS, 0, "external abort on non-linefetch"  },
{ do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault"    },
{ do_bad, SIGBUS, 0, "external abort on translation"    },
{ do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault"    },
{ do_bad, SIGBUS, 0, "external abort on translation"    },
{ do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault"    },
/*
* The following are "imprecise" aborts, which are signalled by bit
* 10 of the FSR, and may not be recoverable.  These are only
* supported if the CPU abort handler supports bit 10.
*/
{ do_bad, SIGBUS,  0, "unknown 16"    },
{ do_bad, SIGBUS,  0, "unknown 17"    },
{ do_bad, SIGBUS,  0, "unknown 18"    },
{ do_bad, SIGBUS,  0, "unknown 19"    },
{ do_bad, SIGBUS,  0, "lock abort"    }, /* xscale */
{ do_bad, SIGBUS,  0, "unknown 21"    },
{ do_bad, SIGBUS,  BUS_OBJERR, "imprecise external abort"    }, /* xscale */
{ do_bad, SIGBUS,  0, "unknown 23"    },
{ do_bad, SIGBUS,  0, "dcache parity error"    }, /* xscale */
{ do_bad, SIGBUS,  0, "unknown 25"    },
{ do_bad, SIGBUS,  0, "unknown 26"    },
{ do_bad, SIGBUS,  0, "unknown 27"    },
{ do_bad, SIGBUS,  0, "unknown 28"    },
{ do_bad, SIGBUS,  0, "unknown 29"    },
{ do_bad, SIGBUS,  0, "unknown 30"    },
{ do_bad, SIGBUS,  0, "unknown 31"    },
};

static struct fsr_info ifsr_info[] = {
{ do_bad, SIGBUS,  0, "unknown 0"    },
{ do_bad, SIGBUS,  0, "unknown 1"    },
{ do_bad, SIGBUS,  0, "debug event"    },
{ do_bad, SIGSEGV, SEGV_ACCERR, "section access flag fault"    },
{ do_bad, SIGBUS,  0, "unknown 4"    },
{ do_translation_fault, SIGSEGV, SEGV_MAPERR, "section translation fault"    },
{ do_bad, SIGSEGV, SEGV_ACCERR, "page access flag fault"    },
{ do_page_fault, SIGSEGV, SEGV_MAPERR, "page translation fault"    },
{ do_bad, SIGBUS, 0, "external abort on non-linefetch"  },
{ do_bad, SIGSEGV, SEGV_ACCERR, "section domain fault"    },
{ do_bad, SIGBUS,  0, "unknown 10"    },
{ do_bad, SIGSEGV, SEGV_ACCERR, "page domain fault"    },
{ do_bad, SIGBUS, 0, "external abort on translation"    },
{ do_sect_fault, SIGSEGV, SEGV_ACCERR, "section permission fault"    },
{ do_bad, SIGBUS, 0, "external abort on translation"    },
{ do_page_fault, SIGSEGV, SEGV_ACCERR, "page permission fault"    },
{ do_bad, SIGBUS,  0, "unknown 16"    },
{ do_bad, SIGBUS,  0, "unknown 17"    },
{ do_bad, SIGBUS,  0, "unknown 18"    },
{ do_bad, SIGBUS,  0, "unknown 19"    },
{ do_bad, SIGBUS,  0, "unknown 20"    },
{ do_bad, SIGBUS,  0, "unknown 21"    },
{ do_bad, SIGBUS,  0, "unknown 22"    },
{ do_bad, SIGBUS,  0, "unknown 23"    },
{ do_bad, SIGBUS,  0, "unknown 24"    },
{ do_bad, SIGBUS,  0, "unknown 25"    },
{ do_bad, SIGBUS,  0, "unknown 26"    },
{ do_bad, SIGBUS,  0, "unknown 27"    },
{ do_bad, SIGBUS,  0, "unknown 28"    },
{ do_bad, SIGBUS,  0, "unknown 29"    },
{ do_bad, SIGBUS,  0, "unknown 30"    },
{ do_bad, SIGBUS,  0, "unknown 31"    },
};

Wednesday, November 20, 2019

How to get different colors in terminal



  • set the LSCOLORS environment variable
  • create an alias for ls so that it shows colors by default
In your ~/.bash_profile add the following:
#export LSCOLORS="EHfxcxdxBxegecabagacad"
export LSCOLORS="exfxcxdxbxegedabagacad"
alias ls='ls -lGH'

alias ls='ls -lGH'        <-----This shows in list format, follow symlinks colorized
The the colors are set by each bit above; the first being foreground and the second being background. The first two characters refer to directories having a bold blue foreground and a light grey background.
However, there's a great online utility to see what each of the colors mean and look like in real time. It will even generate the "code" for you. (I am not affiliated with this at all). It will work in both MacOS/FreeBSD and Linux. Make sure you select the BSD option for macOS.


The order of the attributes are as follows:

1.   directory
2.   symbolic link
3.   socket
4.   pipe
5.   executable
6.   block special
7.   character special
8.   executable with setuid bit set
9.   executable with setgid bit set
10.   directory writable to others, with sticky bit
11.   directory writable to others, without sticky
The color designators are as follows:
a    black
b    red
c    green
d    brown
e    blue
f    magenta
g    cyan
h    light grey
A    bold black, usually shows up as dark grey
B    bold red
C    bold green
D    bold brown, usually shows up as yellow
E    bold blue
F    bold magenta
G    bold cyan
H    bold light grey; looks like bright white
x    default foreground or background


Wednesday, October 16, 2019

Friday, October 4, 2019

Friday, September 20, 2019

Wednesday, September 18, 2019



userspace::insmod.c

int
main(int argc, char *argv[])
{
ret = init_module(file, len, options);


SYSCALL_DEFINE3(init_module, void __user *, umod,
unsigned long, len, const char __user *, uargs)
{

return load_module(&info, uargs, 0);



SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
{

return load_module(&info, uargs, flags);


static int load_module(struct load_info *info, const char __user *uargs,
       int flags)
{

/* Module is ready to execute: parsing args may do that. */
after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
  -32768, 32767, mod,
  unknown_module_param_cb);

return do_init_module(mod);



static int unknown_module_param_cb(char *param, char *val, const char *modname,
   void *arg)
{
struct module *mod = arg;
int ret;

if (strcmp(param, "async_probe") == 0) {
mod->async_probe_requested = true;
return 0;
}

/* Check for magic 'dyndbg' arg */
ret = ddebug_dyndbg_module_param_cb(param, val, modname);
if (ret != 0)
pr_warn("%s: unknown parameter '%s' ignored\n", modname, param);
return 0;
}


/*
 * This is where the real work happens.
 *
 * Keep it uninlined to provide a reliable breakpoint target, e.g. for the gdb
 * helper command 'lx-symbols'.
 */
static noinline int do_init_module(struct module *mod)
{
int ret = 0;
struct mod_initfree *freeinit;

freeinit = kmalloc(sizeof(*freeinit), GFP_KERNEL);
if (!freeinit) {
ret = -ENOMEM;
goto fail;
}
freeinit->module_init = mod->init_layout.base;

/*
* We want to find out whether @mod uses async during init.  Clear

Saturday, May 4, 2019

uninstall/install firefox/chrome on ubuntu


sudo apt-get purge firefox
rm -rf ~/.mozilla
sudo rm -rf /etc/firefox/
sudo rm -rf /usr/lib/firefox
sudo rm -rf /usr/lib/firefox-addons

apt-cache show firefox | grep Version
sudo apt-get install firefox=45.0.2+build1-0ubuntu1
sudo apt-mark hold firefox

wget sourceforge.net/projects/ubuntuzilla/files/mozilla/apt/pool/main/f/firefox-mozilla-build/firefox-mozilla-build_52.0-0ubuntu1_amd64.deb
sudo dpkg -i firefox-mozilla-build_52.0-0ubuntu1_amd64.deb

###################################################
old verions of chrome

https://www.slimjet.com/chrome/google-chrome-old-version.php

sudo apt-get purge google-chrome-stable
sudo apt-get autoremove google-chrome-stable

http://chromedriver.storage.googleapis.com/index.html
chromedriver    chrome
2.46            71-73
2.45            70-72
2.44            69-71
2.43            69-71
2.42            68-70
2.41            67-69
2.40            66-68
2.39            66-68
2.38            65-67
2.37            64-66
2.36            63-65
2.35            62-64
2.34            61-63
2.33            60-62
---------------------
2.28            57+
2.25            54+
2.24            53+
2.22            51+
2.19            44+
2.15            42+

Friday, March 29, 2019

DMA / Invalidate / Flush

Flush: write back the contents of cache to main memory
Invalidate: mark cache lines as invalid so that future reads go to main memory.
Dirty: mark DMA memory region "dirty", so that CPU will invalidate the region

DDR memory -> HW buffer:
1. Flush DDR memory (no flush on HW buffer needed because it's not cacheable)
2. Invalidate DDR memory (so no cache line used during DMA)

https://stackoverflow.com/questions/7132284/dma-cache-coherence-management

Thursday, March 7, 2019

To disable suspend from closing lid


https://help.ubuntu.com/stable/ubuntu-help/power-closelid.html.en

  1. Open the Activities overview and start typing Tweaks.
  2. Click Tweaks (GNOME Tweaks) to open the application.
  3. Click the Power tab.
  4. Switch Suspend when laptop lid is closed to OFF.
  5. Close the Tweaks window.

Friday, March 1, 2019

store / remove ssh key (git passphrase)



********************
*
********************
$ eval $(ssh-agent)
## The output without the eval will look like this:
$ ssh-agent
ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-hvcwJQnSOHOi/agent.125894; export SSH_AUTH_SOCK;
SSH_AGENT_PID=125895; export SSH_AGENT_PID;
echo Agent pid 125895;

After the ssh-agent is started (with the eval). You can add SSH keys with ssh-add

$ ssh-add ~/.ssh/google
$ ssh-add ~/.ssh/id_rsa

With current versions of SSH you can also add the option AddKeysToAgent to the ~/.ssh/config file:

## ~/.ssh/config
AddKeysToAgent yes


********************
* Remove known host
********************
ssh-keygen -R 192.168.123.254

********************
*
********************
~/.bashrc
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
    echo succeeded
    chmod 600 ${SSH_ENV}
    . ${SSH_ENV} > /dev/null
    /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
     . ${SSH_ENV} > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi


********************
* MacBook
********************

As of macOS Sierra 10.12.2 Apple added an ssh_config option called UseKeychain which allows a 'proper' resolution to the problem. Add the following to your ~/.ssh/config file:

Wednesday, February 27, 2019

execute a script on a remote machine over ssh using expect


https://linux.die.net/man/1/expect
https://www.blogger.com/blogger.g?blogID=7297027245100107097#allposts/postNum=0

* clock
https://www.tcl.tk/man/tcl8.5/tutorial/Tcl41.html

on Macbook
brew install expect

on Ubuntu
sudo apt install expect

expect.sh

------------------------------

#!/bin/bash
nodeIp=192.168.1.176

(expect -c '
#exp_internal 1
#set timeout 15
spawn ssh root@'$nodeIp'
#expect {
#        ")? " { send "yes\r" ; exp_continue }
#        "# " { send "\r" }
#        }
expect "# "
send "rm /var/log/messages*\r"
expect "# "
send "reboot\r"
expect "# "
#send "exit\r"
    expect eof ')

------------------------------

#!/bin/bash
#foreach {host user password target} $argv {break}

#set command "ping -c 1 $target"
#send "$command\r"

#log_user 0                   ;# turn off the usual output
#expect -re "(yes/no)"
#send "yes\r"
#sleep 1

nodeIp=192.168.1.176

(
expect -c '
#exp_internal 1
#set timeout 20

set command "i2cget -y 1 0x1c 0x14"

spawn ssh root@'$nodeIp'
#expect {
#        ")? " { send "yes\r" ; exp_continue }
#        "# " { send "\r" }
#        }

expect "~# "
send_user "running $command\r\n"

send "$command\r"
expect "0x04"
send "\r"
# puts "$expect_out(0,string)\n"
if {$expect_out(0,string) == "0x04"} {
puts "output of i2cget -y 1 0x1c 0x14 is 0x04\n"
} else {
puts "False\n"
}
# puts "$expect_out(buffer)"

send "\r"
expect "~# "

send "exit\r"
expect eof '
)

Monday, February 4, 2019

taskset example


-p [process id]
./taskset -p 1760 
pid 1760's current affinity mask: f

/taskset -cp 1760
pid 1760's current affinity list: 0-3


taskset -p 0x4 1760

assign it to core0 and core3
taskset -cp 0,3 9726