kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

关于ksoftirqd进程

blog.chinaunix.net/uid-20737871-id-1881243.html

每个处理器都有一组辅助处理器软中断(和tasklet)的内核线程。当内核中出现大量软中断的时候,这些内核进程就会辅助处理它们。

引入ksoftirq内核线程的原因:

对于软中断,内核会选择在几个特殊时机进行处理。而在中断处理程序返回时处理是最常见的。软中断被触发的频率有时可能很高,更不利的是,处理函数有时还会 字形重复触发,那么就会导致用户空间进程无法获得足够的处理时间,因而处于饥饿状态。单纯的对重新触发的软中断采取不立即处理的策略,也无法让人接受。

最初的解决方案:

1)只要还有被触发并等待处理的软中断,本次执行就要负责处理,重新触发的软中断也在本次执行返回前被处理。这样做可以保证对内核的软中断采取即时处理的 方式,关键在于,对重新触发的软中断也会立即处理。当负载很高的时候,此时若有大量被触发的软中断,而它们本身又会重复触发。系统可能会一直处理软中断根 本不能完成其他任务。

2)不处理重新触发的软中断。在从中断返回的时候,内核和平常一样,也会检查所有挂起的软中断并处理他们。但是,任何自行重新触发的软中断不会马上处理, 它们被放到下一个软中断执行时机去处理。而这个时机通常也就是下一次中断返回的时候。可是,在比较空闲的系统中,立即处理软中断才是比较好的做法。尽管它 能保证用户空间不处于饥饿状态,但它却让软中断忍受饥饿的痛苦,而根本没有好好利用闲置的系统资源。

改进:

最终在内核中实现的方案是不会立即处理处理重新触发的软中断。而作为改进,当大量软中断出现的时候,内核会唤醒一组内核线程来处理这些负载。这些线程在最 低的优先级上运行(nice值是19),这能避免它们跟其他重要的任务抢夺资源。但它们最终肯定会被执行,所以这个折中方案能够保证在软中断负担很中的时 候用户程序不会因为得不到处理时间处于饥饿状态。相应的,也能保证”过量“的软中断终究会得到处理。

每个处理器都有一个这样的线程。所有线程的名字都叫做ksoftirq/n,区别在于n,它对应的是处理器的编号。在一个双CPU的机器上就有两个这样的 线程,分别叫做ksoftirqd/0和ksoftirqd/1。为了保证只要有空闲的处理器,它们就会处理软中断,所以给每个处理器都分配一个这样的线 程。一旦该线程被初始化,它就会执行类似下面这样的死循环:

在kernel/softirq.c中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
static int ksoftirqd(void * __bind_cpu)
{
	set_user_nice(current, 19);
	current->flags |= PF_NOFREEZE;
	set_current_state(TASK_INTERRUPTIBLE);
	while (!kthread_should_stop()) {
		preempt_disable();
		if (!local_softirq_pending()) {
			preempt_enable_no_resched();
			schedule();
			preempt_disable();
		}
		__set_current_state(TASK_RUNNING);
		while (local_softirq_pending()) {
			/* Preempt disable stops cpu going offline.
				If already offline, we'll be on wrong CPU:
				don't process */
			if (cpu_is_offline((long)__bind_cpu))
				goto wait_to_die;
			do_softirq();
			preempt_enable_no_resched();
			cond_resched();
			preempt_disable();
		}
		preempt_enable();
		set_current_state(TASK_INTERRUPTIBLE);
	}
	__set_current_state(TASK_RUNNING);
	return 0;
wait_to_die:
	preempt_enable();
	/* Wait for kthread_stop */
	set_current_state(TASK_INTERRUPTIBLE);
	while (!kthread_should_stop()) {
		schedule();
		set_current_state(TASK_INTERRUPTIBLE);
	}
	__set_current_state(TASK_RUNNING);
	return 0;
}

只要有待处理的软中断(由softirq_pending()函数负责发现),ksoftirq就会调用do_softirq去处理它们。通过重复执行这 样的操作,重新触发的软中断也会被执行。如果有必要,每次迭代后都会调用schedule()以便让更重要的进程得到处理机会。当所有需要执行的操作都完 成以后,该内核线程将自己设置为TASK_INTERRUPTIBLE状态,唤起调度程序选择其他可执行进程投入运行。

只要do_softirq()函数发现已经执行过的内核线程重新触发了它自己,软中断内核线程就会被唤醒.

编译I9507V内核

源码地址 http://opensource.samsung.com/reception/receptionSub.do?method=sub&sub=F&searchValue=9507

好像三星android4.3版本后的bootloader会检测是否三星自编译内核,不是的会开机提示一下,不影响正常使用。

按照README_Kernel.txt的做。

内核中说明是用4.7编译器,但是4.7编译出来的装上去会挂,不知道为什么。
但是换成4.6编译器就没问题。

1
make VARIANT_DEFCONFIG=jftdd_eur_defconfig jf_defconfig SELINUX_DEFCONFIG=selinux_defconfig

最后作成boot.img

1
2
3
4
mkbootimg --kernel zImage --ramdisk boot.img-ramdisk.cpio.gz --base 80200000 --ramdisk_offset 1FF8000 --pagesize 2048 --cmdline "console=null androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x3F ehci-hcd.park=3 maxcpus=4" -o boot.img

tar cf boot.img.tar boot.img
用odin3.10,选择AP项刷入

修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
diff --git a/Makefile b/Makefile
index 16603ac..6d2b29f 100755
--- a/Makefile
+++ b/Makefile
@@ -193,7 +193,7 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
 export KBUILD_BUILDHOST := $(SUBARCH)
 ARCH     ?=arm
-CROSS_COMPILE    ?=/opt/toolchains/arm-eabi-4.7/bin/arm-eabi-
+CROSS_COMPILE    ?=/home/kk/android/gcc-arm-none-eabi-4_6-2012q4/bin/arm-none-eabi-
 
 # Architecture as present in compile.h
 UTS_MACHINE  := $(ARCH)
diff --git a/arch/arm/configs/jftdd_eur_defconfig b/arch/arm/configs/jftdd_eur_defconfig
index 389a204..2c53b92 100755
--- a/arch/arm/configs/jftdd_eur_defconfig
+++ b/arch/arm/configs/jftdd_eur_defconfig
@@ -2,3 +2,5 @@ CONFIG_MACH_JF_EUR=y
 CONFIG_MACH_JFTDD_EUR=y
 CONFIG_EXTRA_FIRMWARE="audience-es325-fw-eur.bin"
 CONFIG_EXTRA_FIRMWARE_DIR="firmware"
+CONFIG_LOCALVERSION="-chn-kk"
+CONFIG_LOCALVERSION_AUTO=n
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 0525927..4dbc5cf 100755
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -98,7 +98,13 @@ extern void printk_tick(void);
 asmlinkage __printf(1, 0)
 int vprintk(const char *fmt, va_list args);
 asmlinkage __printf(1, 2) __cold
-int printk(const char *fmt, ...);
+
+static __always_inline int printk(const char *fmt, ...)
+{
+ return 0;
+}
+
+int orig_printk(const char *s, ...);
 
 /*
  * Special printk facility for scheduler use only, _DO_NOT_USE_ !
diff --git a/include/net/tcp.h b/include/net/tcp.h
index a70c0e4..0d13553 100755
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -140,9 +140,9 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
                                   * for local resources.
                                   */
 
-#define TCP_KEEPALIVE_TIME   (120*60*HZ) /* two hours */
-#define TCP_KEEPALIVE_PROBES 9       /* Max of 9 keepalive probes    */
-#define TCP_KEEPALIVE_INTVL  (75*HZ)
+#define TCP_KEEPALIVE_TIME   (10*60*HZ)  /* 10 mins */
+#define TCP_KEEPALIVE_PROBES 7       /* Max of 7 keepalive probes    */
+#define TCP_KEEPALIVE_INTVL  (60*HZ)
 
 #define MAX_TCP_KEEPIDLE 32767
 #define MAX_TCP_KEEPINTVL    32767
diff --git a/kernel/printk.c b/kernel/printk.c
index f7c85aa..80d2cd0 100755
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -995,7 +995,7 @@ static int have_callable_console(void)
  * See the vsnprintf() documentation for format string extensions over C99.
  */
 
-asmlinkage int printk(const char *fmt, ...)
+asmlinkage int orig_printk(const char *fmt, ...)
 {
  va_list args;
  int r;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5f5959c..03ba861 100755
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6912,7 +6912,7 @@ void __init sched_init_smp(void)
 }
 #endif /* CONFIG_SMP */
 
-const_debug unsigned int sysctl_timer_migration = 1;
+const_debug unsigned int sysctl_timer_migration = 0;
 
 int in_sched_functions(unsigned long addr)
 {
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 10def3a..a68e108 100755
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -75,7 +75,7 @@
 #include <asm/unaligned.h>
 #include <net/netdma.h>
 
-int sysctl_tcp_timestamps __read_mostly = 1;
+int sysctl_tcp_timestamps __read_mostly = 0;
 int sysctl_tcp_window_scaling __read_mostly = 1;
 int sysctl_tcp_sack __read_mostly = 1;
 int sysctl_tcp_fack __read_mostly = 1;
@@ -1300,7 +1300,7 @@ static int tcp_match_skb_to_sack(struct sock *sk, struct sk_buff *skb,
          unsigned int new_len = (pkt_len / mss) * mss;
          if (!in_sack && new_len < pkt_len) {
              new_len += mss;
-             if (new_len > skb->len)
+             if (new_len >= skb->len)
                  return 0;
          }
          pkt_len = new_len;
@@ -4782,7 +4782,7 @@ restart:
      int copy = SKB_MAX_ORDER(header, 0);
 
      /* Too big header? This can happen with IPv6. */
-     if (copy < 0)
+     if (copy <= 0)
          return;
      if (end - start < copy)
          copy = end - start;
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 3cabafb..6b36c25 100755
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -27,7 +27,7 @@
 #include <net/inet_common.h>
 #include <net/xfrm.h>
 
-int sysctl_tcp_syncookies __read_mostly = 1;
+int sysctl_tcp_syncookies __read_mostly = 0;
 EXPORT_SYMBOL(sysctl_tcp_syncookies);
 
 int sysctl_tcp_abort_on_overflow __read_mostly;
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index 72b5088..7c54171 100755
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -50,7 +50,7 @@ static unsigned int sctp_timeouts[SCTP_CONNTRACK_MAX] __read_mostly = {
  [SCTP_CONNTRACK_CLOSED]         = 10 SECS,
  [SCTP_CONNTRACK_COOKIE_WAIT]        = 3 SECS,
  [SCTP_CONNTRACK_COOKIE_ECHOED]      = 3 SECS,
- [SCTP_CONNTRACK_ESTABLISHED]        = 5 DAYS,
+ [SCTP_CONNTRACK_ESTABLISHED]        = 20 MINS,
  [SCTP_CONNTRACK_SHUTDOWN_SENT]      = 300 SECS / 1000,
  [SCTP_CONNTRACK_SHUTDOWN_RECD]      = 300 SECS / 1000,
  [SCTP_CONNTRACK_SHUTDOWN_ACK_SENT]  = 3 SECS,
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index 0d07a1d..84d55e4 100755
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -32,7 +32,7 @@
 /* "Be conservative in what you do,
     be liberal in what you accept from others."
     If it's non-zero, we mark only out of window RST segments as INVALID. */
-static int nf_ct_tcp_be_liberal __read_mostly = 0;
+static int nf_ct_tcp_be_liberal __read_mostly = 1;
 
 /* If it is set to zero, we disable picking up already established
    connections. */
@@ -67,7 +67,7 @@ static const char *const tcp_conntrack_names[] = {
 static unsigned int tcp_timeouts[TCP_CONNTRACK_TIMEOUT_MAX] __read_mostly = {
  [TCP_CONNTRACK_SYN_SENT]    = 2 MINS,
  [TCP_CONNTRACK_SYN_RECV]    = 60 SECS,
- [TCP_CONNTRACK_ESTABLISHED] = 5 DAYS,
+ [TCP_CONNTRACK_ESTABLISHED] = 20 MINS,
  [TCP_CONNTRACK_FIN_WAIT]    = 2 MINS,
  [TCP_CONNTRACK_CLOSE_WAIT]  = 60 SECS,
  [TCP_CONNTRACK_LAST_ACK]    = 30 SECS,
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 857ea4f..742fe12 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -184,7 +184,7 @@ else
  # LOCALVERSION= is not specified
  if test "${LOCALVERSION+set}" != "set"; then
      scm=$(scm_version --short)
-     res="$res${scm:++}"
+     res="$res${scm:+}"
  fi
 fi
 

img.ext4格式

工具 https://github.com/abcdxyzk/ext4_utils

android5.0以上请用ubuntu自带命令

1
sudo apt-get install android-tools-fsutils

该工具包含:

1
2
3
4
5
6
7
8
9
10
11
/usr/bin/ext2simg
/usr/bin/ext4fixup
/usr/bin/img2simg
/usr/bin/make_ext4fs
/usr/bin/mkuserimg
/usr/bin/simg2img
/usr/bin/simg2simg
/usr/bin/simg_dump
/usr/bin/test_ext4fixup
/usr/share/doc/android-tools-fsutils/changelog.Debian.gz
/usr/share/doc/android-tools-fsutils/copyright

一、转换源文件为ext4格式

然后,我们可以使用./simg2img src des命令来转换system.img.ext4格式文件了

1
./simg2img system.img.ext4 system.img

二、挂载镜像到指定目录

然后挂载此img到一个目录上

1
mount -o loop system.img sysmain

成功挂载。然后你就可以进入目录了查看里面的文件了!!!!!

三、修改镜像内的文件

这时候可以进入挂载的目录mysys里面查看各个文件,甚至是修改了。不过这时候要注意一点,就是保持文件的原始权限。

四、打包文件

当你所有文件搞定后,下来需要一个命令来打包了。

1
2
3
4
5
# android5.0 以后用该命令, file_contexts来自"/"目录, 所以要先刷一次一体包提取
make_ext4fs -S file_contexts -s -l 2365587456 -a system system.img.ext4 system

# 老命令
./mkuserimg.sh -s sysmain systest.img.ext4 ext4 tmp 512M

这里需要注意,temp是我在当前目录新建立的一个目录,后面的512M是这个镜像打包后占用空间大小。如果你不知道你的镜像包应该多大,你查看你景象挂载到目录后,这个景象分区的大小。

恩,当你完成以上步骤,新的systest.img.ext4成功生成了,好了,你可以在fastboot模式下刷入了!!!