易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux Kernel時序的三種機制

最近在寫Driver時,常常遇到需要「等待一段時間」再處理的動作,以往我都傻傻的用msleep()或mdelay(),殊不知這種busy waiting會hold住cpu資源,在這段期間內都無法讓給其他process執行,時間短(10ms以下等級)或許還可以,太長就不行了,所以需要Kernel本身就有提供的「時序」機制來做處理,於是我漸漸學會了如何使用Timer、Tasklet和Workqueue的用法,在O'Reilly的Linux Device Drivers第七章有詳細的講解,我將書上的精華茲簡單整理如下:
##CONTINUE##
一、Timer
#include <linux/timer.h>
struct timer_list
{
/* ... */
unsigned long expires;//期望運行的 jiffies 值
void (*function)(unsigned long);
unsigned long data;//傳給function的參數
};//使用前必須初始化
void init_timer(struct timer_list *timer);
//初始化一個timer_list
struct timer_list TIMER_INITIALIZER(_function, _expires, _data);
//初始化一個靜態的timer_list
void add_timer(struct timer_list * timer);
int mod_timer(struct timer_list *timer, unsigned long expires);
int del_timer(struct timer_list * timer);
int del_timer_sync(struct timer_list *timer);
//同 del_timer 一樣,但保證函數return時,定時器函數不在任何 CPU 上運行
//避免在SMP 系統上競爭
int timer_pending(const struct timer_list * timer);
//返回真或假來指示是否定時器已被運行
二、Tasklet
#include <linux/interrupt.h>
struct tasklet_struct {
/* ... */
void (*func)(unsigned long);
unsigned long data;
};
void tasklet_init(struct tasklet_struct *t,
void (*func)(unsigned long), unsigned long data);
//將定義好的結構體初始化,才可用
DECLARE_TASKLET(name, func, data);
//直接申明就可用了
DECLARE_TASKLET_DISABLED(name, func, data);
void tasklet_disable(struct


相关文档:

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

Linux环境的AMP安装 mbstring安装


Linux下mbstring安装
1、用cd命令进入php的源代码目录下的etc/mbstring目录下,如“/src/php5.2.5”,即“cd /src/php5.2.5”;
2、>/usr/local/php/bin/phpize (假设php安装在/usr/local/php目录下)
3、编译配置,>./configure --with-php-config=/usr/local/php/bin/php-config
4、执行 ......

Linux环境的AMP安装 MEMCACHED安装


MEMCACHED安装
一、服务端。先安装libevent,再安装memcached。(注:libevent是一套跨平台的事件处理接口的封装,能够兼容包括:Windows/Linux/BSD/Solaris等操作系统的事件处理)
1、下载最新版本的libevent和memcached,笔者的安装目录为/soft
>cd /soft
>wget http://www.dange.com/memcached/dist/memcach ......

php加入linux系统命令


假设php安装在/usr/local/php5/bin/php,初始在命令行执行PHP的时候要输入一长串的路径,eg:
$>/usr/local/php5/bin/php phpinfo.php
非常的麻烦,现在只需将php拷贝至usr/sbin目录即可直接使用php命令,eg:
$>cp /usr/local/php5/bin/php /usr/sbin/
$>php phpinfo.php
......

用户模式Linux之初次体验

用户模式Linux (User Mode Linux), 缩写为UML。顾名思义,UML就是在一个可以在用户空间运行的linux内核。
UML能够为kernel虚拟一些实际的物理设备,启动UML只需要要指定一个root文件系统的image文件。UML实际上也是一种虚拟化技术。
 
UML的好处
第一,做一个虚拟服务器,UML可以以安全的方式运行在用户空间,它可 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号