Linux API/linux2015. 11. 6. 11:09


커널 모듈 소스에서 보다 발견

결론은.. 걍 포인터?


[링크 : http://lxr.free-electrons.com/source/arch/mn10300/include/asm/io.h#L38]


109 #ifndef readb

110 #define readb readb

111 static inline u8 readb(const volatile void __iomem *addr)

112 {

113         return __raw_readb(addr);

114 }

115 #endif

116 

117 #ifndef readw

118 #define readw readw

119 static inline u16 readw(const volatile void __iomem *addr)

120 {

121         return __le16_to_cpu(__raw_readw(addr));

122 }

123 #endif

124 

125 #ifndef readl

126 #define readl readl

127 static inline u32 readl(const volatile void __iomem *addr)

128 {

129         return __le32_to_cpu(__raw_readl(addr));

130 }

131 #endif

132 

133 #ifdef CONFIG_64BIT

134 #ifndef readq

135 #define readq readq

136 static inline u64 readq(const volatile void __iomem *addr)

137 {

138         return __le64_to_cpu(__raw_readq(addr));

139 }

140 #endif

141 #endif /* CONFIG_64BIT */

142 

143 #ifndef writeb

144 #define writeb writeb

145 static inline void writeb(u8 value, volatile void __iomem *addr)

146 {

147         __raw_writeb(value, addr);

148 }

149 #endif

150 

151 #ifndef writew

152 #define writew writew

153 static inline void writew(u16 value, volatile void __iomem *addr)

154 {

155         __raw_writew(cpu_to_le16(value), addr);

156 }

157 #endif

158 

159 #ifndef writel

160 #define writel writel

161 static inline void writel(u32 value, volatile void __iomem *addr)

162 {

163         __raw_writel(__cpu_to_le32(value), addr);

164 }

165 #endif

166 

167 #ifdef CONFIG_64BIT

168 #ifndef writeq

169 #define writeq writeq

170 static inline void writeq(u64 value, volatile void __iomem *addr)

171 {

172         __raw_writeq(__cpu_to_le64(value), addr);

173 }

174 #endif

175 #endif /* CONFIG_64BIT */


[링크 : http://lxr.free-electrons.com/source/include/asm-generic/io.h#L127] 


'Linux API > linux' 카테고리의 다른 글

리눅스 동적 라이브러리(*.so) 사용하기  (0) 2016.04.04
리눅스 커널 모듈 관련 문서  (0) 2015.11.06
리눅스 모듈 프로그래밍 관련  (0) 2015.10.30
linux open mode  (0) 2015.10.29
named pipe / mkfifo()  (0) 2015.10.27
Posted by 구차니
Linux API/linux2015. 10. 30. 15:32


int register_blkdev (unsigned int major, const char * name);

[링크 : https://www.kernel.org/doc/htmldocs/kernel-api/API-register-blkdev.html]


int __register_chrdev ( unsigned int major,

  unsigned int baseminor,

  unsigned int count,

  const char * name,

  const struct file_operations * fops);


[링크 : http://linux.die.net/lkmpg/x892.html]

[링크 : http://linux.die.net/lkmpg/x569.html]

[링크 : https://wiki.kldp.org/KoreanDoc/html/EmbeddedKernel-KLDP/device-understanding.html]

'Linux API > linux' 카테고리의 다른 글

리눅스 커널 모듈 관련 문서  (0) 2015.11.06
readl(), writel()  (0) 2015.11.06
linux open mode  (0) 2015.10.29
named pipe / mkfifo()  (0) 2015.10.27
signal  (0) 2015.10.26
Posted by 구차니
Linux API/linux2015. 10. 29. 11:08

퍼미션 비트 관련 플래그 정리




[링크 : http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html]

'Linux API > linux' 카테고리의 다른 글

readl(), writel()  (0) 2015.11.06
리눅스 모듈 프로그래밍 관련  (0) 2015.10.30
named pipe / mkfifo()  (0) 2015.10.27
signal  (0) 2015.10.26
select()  (0) 2015.10.26
Posted by 구차니
Linux API/linux2015. 10. 27. 13:17


[링크 : http://akj61300.blog.me/80133137262]


전혀 관련없는 프로세스들 사이에서 pipe를 이용해서 통신을 하려면 pipe에 이름이 주어져야 한다. named pipe 를 만든 이유다.

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/system_programing/Book_LSP/ch08_IPC]


만들어진 fifo 파일의 크기는 해당 파일에 대한 입력이 있더라 하더라도 그 크기는 언제나 0인데 이유는 입력이 파일로 쌓이지 않고, 커널에서 이를 처리하기 때문 이다. 만들어진 fifo 파일은 PIPE 와 달리, 프로세스가 종료하거나, 시스템을 리부팅 시키더라도 사라지지 않으며(파일이니 당연하다), 직접 지워줄때까지 살아있게 된다. 리눅스에서는 FIFO를 만들도록 도와주는 mkfifo(2)라는 프로그램도 있으므로, FIFO 파일을 만들기 위해서 굳이 위의 예제처럼 fifo.c 파일을 만들필요는 없을 것이다.


만들어진 FIFO 파일로의 읽기및 쓰기는 보통의 파일을 위해서 사용하는 open(2)과 fopen(3) 등 일반적인 파일 열기/엑세스 함수군을 사용하면 된다.

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/system_programing/IPC/FIFO]


#include <sys/types.h>

#include <sys/stat.h>


int mkfifo(const char *pathname, mode_t mode);


[링크 : http://linux.die.net/man/3/mkfifo]


+

네임드 파이프 사용법

[링크 : http://unabated.tistory.com/entry/named-pipe-FIFO]

'Linux API > linux' 카테고리의 다른 글

리눅스 모듈 프로그래밍 관련  (0) 2015.10.30
linux open mode  (0) 2015.10.29
signal  (0) 2015.10.26
select()  (0) 2015.10.26
mmap / ioremap  (0) 2015.10.21
Posted by 구차니
Linux API/linux2015. 10. 26. 15:17

#include <signal.h>


int sigemptyset(sigset_t *set);

int sigfillset(sigset_t *set);

int sigaddset(sigset_t *set, int signum);

int sigdelset(sigset_t *set, int signum);

int sigismember(const sigset_t *set, int signum);

int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);

int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);


struct sigaction {

    void     (*sa_handler)(int);

    void     (*sa_sigaction)(int, siginfo_t *, void *);

    sigset_t   sa_mask;

    int        sa_flags;

    void     (*sa_restorer)(void);

};


int signum;

SIGTERM

SIGINT

SIGHUP

SIGFPE

...


[링크 : http://linux.die.net/man/3/sigemptyset]

[링크 : http://linux.die.net/man/3/sigfillset]

[링크 : http://linux.die.net/man/3/sigaddset]

[링크 : http://linux.die.net/man/3/sigdelset]

[링크 : http://linux.die.net/man/2/sigaction]

[링크 : http://linux.die.net/man/2/sigprocmask]

'Linux API > linux' 카테고리의 다른 글

linux open mode  (0) 2015.10.29
named pipe / mkfifo()  (0) 2015.10.27
select()  (0) 2015.10.26
mmap / ioremap  (0) 2015.10.21
리눅스 모듈 - 세마포어 / 뮤텍스  (0) 2015.10.21
Posted by 구차니
Linux API/linux2015. 10. 26. 10:48


[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/select]

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Network_Programing/Documents/select]

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/system_programing/File/select]


[링크 : http://mintnlatte.tistory.com/313]

[링크 : http://ospace.tistory.com/147]

[링크 : http://forum.falinux.com/zbxe/index.php?document_srl=405838]

'Linux API > linux' 카테고리의 다른 글

named pipe / mkfifo()  (0) 2015.10.27
signal  (0) 2015.10.26
mmap / ioremap  (0) 2015.10.21
리눅스 모듈 - 세마포어 / 뮤텍스  (0) 2015.10.21
linux kernel module module_init() 매크로  (0) 2015.10.21
Posted by 구차니
Linux API/linux2015. 10. 21. 14:50

die.net에서 ioremap 찾으니 mmap이 나오는 신기한 현상..

그래서 찾아보니..


ioremap은 커널에서 쓰는 함수

mmap은 유저레벨에서 사용하는 함수


즉, 모듈에서는 ioremap

어플리케이션에서는 mmap으로


[링크 : http://torystory.tistory.com/20]



ioremap 가상주소 -> 물리주소

iounmap 물리주소 -> 가상주소

[링크 : http://mudweb.tistory.com/11]

'Linux API > linux' 카테고리의 다른 글

signal  (0) 2015.10.26
select()  (0) 2015.10.26
리눅스 모듈 - 세마포어 / 뮤텍스  (0) 2015.10.21
linux kernel module module_init() 매크로  (0) 2015.10.21
리눅스 타이머 예제 setitimer() / sigaction()  (0) 2015.10.13
Posted by 구차니
Linux API/linux2015. 10. 21. 13:32

써봐야지 머... ㅠㅠ


[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/system_programing/IPC/semaphores]

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Thread/Beginning/Mutex]

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/system_programing/Book_LSP/ch07_Thread]


sema_init()

[링크 : http://lxr.free-electrons.com/source/include/linux/semaphore.h]



뮤텍스 = 바이너리 세마포어


우선 하는 일에 대해서 mutex는 binary semaphore와 많이 동일하고요.

구조적인 측면과 동작 측면에서는 mutex는 owner라는 개념 있는데 반해 binary semaphore는 owner라는 개념이 없다는 차이가 있습니다.

 

이로 인해 mutex는 lock한 task만 unlock 할수 있는데 반해 semaphore는 아무 task나 unlock이 가능하죠.

[링크 : http://www.iamroot.org/xe/QnA/36692]


[링크 : http://ninako21.tistory.com/500]

[링크 : http://topnanis.tistory.com/195]



+ 2015.10.29

[링크 : http://egloos.zum.com/tiger5net/v/5537603]

'Linux API > linux' 카테고리의 다른 글

select()  (0) 2015.10.26
mmap / ioremap  (0) 2015.10.21
linux kernel module module_init() 매크로  (0) 2015.10.21
리눅스 타이머 예제 setitimer() / sigaction()  (0) 2015.10.13
clock_gettime  (0) 2015.08.09
Posted by 구차니
Linux API/linux2015. 10. 21. 12:24

module_init()는 __initcall()로 치환되고

__initcal()은 static inicall_t __initcall_modulename __init_call = modulename

으로 치환되어

initcall_t 타입의 정적변수로 생성된다.

결국은... 다른 파일에서 __init_call 하나로 끌어갈수 있으려나?

(물론 내부 인터페이스 함수가 존재할 듯?)


#define __initcall(fn) static initcall_t __initcall_##fn __init_call = fn

#define module_init(x)  __initcall(x);


[링크 : http://www.compsoc.man.ac.uk/~moz/kernelnewbies/documents/initcall/kernel.html]


#define __exitcall(fn) \

static exitcall_t __exitcall_##fn __exit_call = fn

#define module_exit(x) __exitcall(x);


[링크 : https://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/include/linux/init.h] 


#define module_param(name, type, perm)                          \

        module_param_named(name, name, type, perm)


#define module_param_named(name, value, type, perm)                        \

        param_check_##type(name, &(value));                                \

        module_param_cb(name, &param_ops_##type, &value, perm);            \

        __MODULE_PARM_TYPE(name, #type)


#define module_param_cb(name, ops, arg, perm)                                 \

        __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)


#define __module_param_call(prefix, name, ops, arg, perm, level, flags) \

        /* Default value instead of permissions? */                     \

        static const char __param_str_##name[] = prefix #name;          \

        static struct kernel_param __moduleparam_const __param_##name   \

        __used                                                          \

    __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \

        = { __param_str_##name, THIS_MODULE, ops,                       \

            VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }


#define __moduleparam_const const


[링크 : http://lxr.free-electrons.com/source/include/linux/moduleparam.h]


[링크 : http://www.joinc.co.kr/.../Site/Embedded/Documents/WritingDeviceDriversInLinux]

[링크 : https://www.kernel.org/doc/htmldocs/kernel-hacking/routines-init-again.html]

'Linux API > linux' 카테고리의 다른 글

select()  (0) 2015.10.26
mmap / ioremap  (0) 2015.10.21
리눅스 모듈 - 세마포어 / 뮤텍스  (0) 2015.10.21
리눅스 타이머 예제 setitimer() / sigaction()  (0) 2015.10.13
clock_gettime  (0) 2015.08.09
Posted by 구차니
Linux API/linux2015. 10. 13. 16:09


ITIMER_REAL

decrements in real time, and delivers SIGALRM upon expiration.

실시간으로 감소하고 만료시 SIGALRM을 전송한다.


ITIMER_VIRTUAL

decrements only when the process is executing, and delivers SIGVTALRM upon expiration.

프로세스가 실행중잉 동안만 감소하고 만료시 SIGVTALRM을 전송한다.


ITIMER_PROF

decrements both when the process executes and when the system is executing on behalf of the process. Coupled with ITIMER_VIRTUAL, this timer is usually used to profile the time spent by the application in user and kernel space. SIGPROF is delivered upon expiration.

프로세스가 실행중이거나 시스템이 프로세스 대신 작동하는 동안에도 감소한다. ITIMER_VITUAL과 결합하여 유저 시간과 커널 시간을 프로파일링 하는데 사용된다. SIGPROF가 만료시 전송한다.


Timer values are defined by the following structures:

struct itimerval {

    struct timeval it_interval; /* next value */

    struct timeval it_value;    /* current value */

};


struct timeval {

    time_t      tv_sec;         /* seconds */

    suseconds_t tv_usec;        /* microseconds */

};


The function getitimer() fills the structure pointed to by curr_value with the current setting for the timer specified by which (one of ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF). The element it_value is set to the amount of time remaining on the timer, or zero if the timer is disabled. Similarly, it_interval is set to the reset value.

it_value 값은 타이머의 남은 값을 설정하거나 타이머를 사용하지 않기 위해 0으로 설정한다. 유사하게 it_interval는 초기화 값을 설정한다.

The function setitimer() sets the specified timer to the value in new_value. If old_value is non-NULL, the old value of the timer is stored there.


Timers decrement from it_value to zero, generate a signal, and reset to it_interval. A timer which is set to zero (it_value is zero or the timer expires and it_interval is zero) stops.

it_value로 부터 0으로 타이머가 감소하고, 시그널을 생성하고, it_interval로 초기화 한다. 타이머가 0으로 설정되면 정지한다(it_value가 0이거나 타이머가 만료되고 it_interval이 0일 경우)


Both tv_sec and tv_usec are significant in determining the duration of a timer.


Timers will never expire before the requested time, but may expire some (short) time afterward, which depends on the system timer resolution and on the system load; see time(7). (But see BUGS below.) Upon expiration, a signal will be generated and the timer reset. If the timer expires while the process is active (always true for ITIMER_VIRTUAL) the signal will be delivered immediately when generated. Otherwise the delivery will be offset by a small time dependent on the system loading.

[링크 : http://linux.die.net/man/2/setitimer]


그래서 둘다 설정하지 않으면 멈추는 거구나..

다만. it_value의 값은 초기 1회에 대한 타이머이고

it_interval의 값은 2회 부터의 값에 대한 타이머가 된다.

timer.it_value.tv_sec = 0;

timer.it_value.tv_usec = 250000;

timer.it_interval.tv_sec = 0;

timer.it_interval.tv_usec = 250000;


[링크 : http://linuxspot.tistory.com/28] 


[링크 : https://kldp.org/node/132754]

[링크 : http://manofpro.tistory.com/290]

[링크 : http://forum.falinux.com/zbxe/index.php?document_srl=413903]


[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/article/Timesr_in_Linux]

'Linux API > linux' 카테고리의 다른 글

select()  (0) 2015.10.26
mmap / ioremap  (0) 2015.10.21
리눅스 모듈 - 세마포어 / 뮤텍스  (0) 2015.10.21
linux kernel module module_init() 매크로  (0) 2015.10.21
clock_gettime  (0) 2015.08.09
Posted by 구차니