'Linux API'에 해당되는 글 135건

  1. 2022.10.20 ‘F_SETPIPE_SZ’ undeclared
  2. 2022.10.18 linux fifo
  3. 2022.10.17 SIGPIPE
  4. 2022.10.11 linux ipc 최대 데이터 길이
  5. 2022.09.21 ipc 성능 비교
  6. 2022.09.21 posix message queue
  7. 2022.09.20 zeroMQ
  8. 2022.07.14 kms - Kernel Mode Setting
  9. 2022.07.13 v4l2 debug
  10. 2022.07.06 v4l2-ctl 밝기 조절
Linux API/linux2022. 10. 20. 10:50

커널이 5.4.0 이라 그런가

해당 선언을 해주어야 에러가 사라진다.

 

#define _GNU_SOURCE

[링크 : https://stackoverflow.com/questions/25411892/f-setpipe-sz-undeclared]

 

 

Defining _GNU_SOURCE has nothing to do with license and everything to do with writing (non-)portable code. If you define _GNU_SOURCE, you will get:
  1. access to lots of nonstandard GNU/Linux extension functions
  2. access to traditional functions which were omitted from the POSIX standard (often for good reason, such as being replaced with better alternatives, or being tied to particular legacy implementations)
  3. access to low-level functions that cannot be portable, but that you sometimes need for implementing system utilities like mount, ifconfig, etc.
  4. broken behavior for lots of POSIX-specified functions, where the GNU folks disagreed with the standards committee on how the functions should behave and decided to do their own thing.
As long as you're aware of these things, it should not be a problem to define _GNU_SOURCE, but you should avoid defining it and instead define _POSIX_C_SOURCE=200809L or _XOPEN_SOURCE=700 when possible to ensure that your programs are portable.
In particular, the things from _GNU_SOURCE that you should never use are #2 and #4 above.
 

[링크 : https://stackoverflow.com/questions/5582211/what-does-define-gnu-source-imply]

 

호환성 지정 매크로

[링크 : https://m.blog.naver.com/netiz21/150015716721]

 

#include <fcntl.h> 대신

#include <linux/fcntl.h> 하면 _GNU_SOURCE를 해주지 않아도 되긴 한데

다른데서 경고가 뜨니 알아서 써야 할 듯.

/usr/include/linux/fcntl.h:28:#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
/usr/include/linux/fcntl.h:29:#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)

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

iio(industrial io) 문서  (0) 2022.11.11
mkpipe 와 poll  (0) 2022.10.26
linux fifo  (0) 2022.10.18
SIGPIPE  (0) 2022.10.17
linux ipc 최대 데이터 길이  (0) 2022.10.11
Posted by 구차니
Linux API/linux2022. 10. 18. 18:20

특이하다면 특이하고, 당연하다면 당연하게

fifo는 쓸 녀석과, 읽을 녀석이 둘다 요청이 들어올때 까지 open() 에서 blocking 된다.

 

strace를 이용해서 확인해보면 각각 실행할 경우

O_RDONLY를 주던 O_WRONLY를 주던 간에 open() 함수에서 block 되어있다

두개 프로그램이 read/write pair가 만들어지면 그제서야 open()을 넘어가게 된다.

open()을 non_block 으로 해서 name pipe의 pair가 만들어지길 기다리는 것도 방법 일 듯.

 

$ strace ./rx
openat(AT_FDCWD, "/tmp/fifo", O_RDONLY
$ strace ./tx 2
openat(AT_FDCWD, "/tmp/fifo", O_WRONLY

[링크 : https://tutorialspoint.dev/computer-science/operating-systems/named-pipe-fifo-example-c-program]

 

걍 이렇게 하고 나서 해보면 되려나?

int fifo_fd = open(fifo_path, O_RDONLY | O_NONBLOCK);
FILE *fp = fdopen(fifo_fd, "r");

[링크 : https://cboard.cprogramming.com/c-programming/89358-nonblocking-fifo.html]

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

mkpipe 와 poll  (0) 2022.10.26
‘F_SETPIPE_SZ’ undeclared  (0) 2022.10.20
SIGPIPE  (0) 2022.10.17
linux ipc 최대 데이터 길이  (0) 2022.10.11
ipc 성능 비교  (0) 2022.09.21
Posted by 구차니
Linux API/linux2022. 10. 17. 17:56

mkfifo()를 이용하여 named pipe를 해보는데

받는 쪽이 사라지니 보내는 애가 갑자기 에러도 없이 죽어

gdb로 확인해보니 SIGPIPE가 전달되었고 그로 인해서 프로세스가 종료 된 것으로 보인다.

Program received signal SIGPIPE, Broken pipe.
0x00007ffff7af2104 in __GI___libc_write (fd=3, buf=0x7ffff76e1010, nbytes=3145728)
    at ../sysdeps/unix/sysv/linux/write.c:27
27      ../sysdeps/unix/sysv/linux/write.c: 그런 파일이나 디렉터리가 없습니다.

[링크 : https://jacking75.github.io/linux_socket_sigpipe/]

 

gdb 에서 무시하게 하려면 아래의 명령어를 입력하라고 한다.

handle SIGPIPE nostop pass pass

[링크 : http://egloos.zum.com/mirine35/v/5057019]

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

‘F_SETPIPE_SZ’ undeclared  (0) 2022.10.20
linux fifo  (0) 2022.10.18
linux ipc 최대 데이터 길이  (0) 2022.10.11
ipc 성능 비교  (0) 2022.09.21
posix message queue  (0) 2022.09.21
Posted by 구차니
Linux API/linux2022. 10. 11. 14:39

ipc 타입에 따라 작다면 작고, 크다면 큰 용량이 할당되어 있다

 

pipe

$ cat /proc/sys/fs/pipe-max-size
1048576

[링크 : https://unix.stackexchange.com/questions/11946]

uds (UNIX Domain Socket)

$ cat /proc/sys/net/core/wmem_max
212992

[링크 : https://stackoverflow.com/questions/21856517]

 

message queue

$ sysctl -a |grep kernel.msg
kernel.msgmax = 8192
kernel.msgmnb = 16384
kernel.msgmni = 32000

[링크 : https://dobby-the-house-elf.tistory.com/402]

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

linux fifo  (0) 2022.10.18
SIGPIPE  (0) 2022.10.17
ipc 성능 비교  (0) 2022.09.21
posix message queue  (0) 2022.09.21
zeroMQ  (0) 2022.09.20
Posted by 구차니
Linux API/linux2022. 9. 21. 19:08

zmq는 이런데서는 확 떨어지는 구나

 

Shared Memory > MQ > UDS > FIFO > Pipe > TCP 이런식인데

POSIX Message Queue가 생각외로 성능이 잘 나와서 놀랍다.

IPC Message rate
Pipe 36539 msg/s
FIFOs (named pipes)  26246 msg/s
Message Queue  67920 msg/s
Shared Memory  3821893 msg/s
TCP sockets 22483 msg/s
Unix domain sockets  40683 msg/s
ZeroMQ  15414 msg/s

 

[링크 : https://stackoverflow.com/questions/50171306/message-queue-vs-tcp-ip-socket-which-ipc-is-faster-in-linux]

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

SIGPIPE  (0) 2022.10.17
linux ipc 최대 데이터 길이  (0) 2022.10.11
posix message queue  (0) 2022.09.21
zeroMQ  (0) 2022.09.20
파일 존재유무 확인하기  (0) 2022.02.11
Posted by 구차니
Linux API/linux2022. 9. 21. 19:01

4세대 벤치에서는 mq가 udp sock보다 빠르다고

https://the-linux-channel.the-toffee-project.org/index.php?page=8-tutorials-research-socket-overhead-in-linux-vs-message-queues-and-benchmarking

https://reakwon.tistory.com/m/209

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

linux ipc 최대 데이터 길이  (0) 2022.10.11
ipc 성능 비교  (0) 2022.09.21
zeroMQ  (0) 2022.09.20
파일 존재유무 확인하기  (0) 2022.02.11
select, poll, epoll  (0) 2021.11.02
Posted by 구차니
Linux API/linux2022. 9. 20. 14:43

ZMQ 혹은 0MQ 라고도 쓰는것 같은데 접속 모델부터 좀 찾아 보는 중

 

REQ-REP는 단순(?)한 요청-응답 모델이고

PUB-SUB는 서버에 의한 broadcast 모델 pipeline은 아직 모르겠다.

REQuest-REPly
PUBlisher - SUBscriber
PUSH- PULL (pipeline)

[링크 : https://soooprmx.com/zmq의-기본-개념들/]

[링크 : https://makersweb.net/opensource/19422]

[링크 : https://zeromq.org/]

 

Figure 2 - Request-Reply Figure 4 - Publish-Subscribe Figure 5 - Parallel Pipeline
Figure 6 - Fair Queuing    
   

[링크 : https://zguide.zeromq.org/docs/chapter1/]

 

Shared Queue (DEALER and ROUTER sockets)
In the Hello World client/server application, we have one client that talks to one service. However, in real cases we usually need to allow multiple services as well as multiple clients. This lets us scale up the power of the service (many threads or processes or nodes rather than just one). The only constraint is that services must be stateless, all state being in the request or in some shared storage such as a database.

[링크 : https://zguide.zeromq.org/docs/chapter2/]

 

Request-Reply Combinations
We have four request-reply sockets, each with a certain behavior. We’ve seen how they connect in simple and extended request-reply patterns. But these sockets are building blocks that you can use to solve many problems.

These are the legal combinations:

REQ to REP
DEALER to REP
REQ to ROUTER
DEALER to ROUTER
DEALER to DEALER
ROUTER to ROUTER

[링크 : https://zguide.zeromq.org/docs/chapter3/]

 

Messaging Patterns

Underneath the brown paper wrapping of ZeroMQ’s socket API lies the world of messaging patterns. ZeroMQ patterns are implemented by pairs of sockets with matching types.
The built-in core ZeroMQ patterns are:
  • Request-reply, which connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern.
  • Pub-sub, which connects a set of publishers to a set of subscribers. This is a data distribution pattern.
  • Pipeline, which connects nodes in a fan-out/fan-in pattern that can have multiple steps and loops. This is a parallel task distribution and collection pattern.
  • Exclusive pair, which connects two sockets exclusively. This is a pattern for connecting two threads in a process, not to be confused with “normal” pairs of sockets.
XPUB socket
Same as PUB except that you can receive subscriptions from the peers in form of incoming messages. Subscription message is a byte 1 (for subscriptions) or byte 0 (for unsubscriptions) followed by the subscription body. Messages without a sub/unsub prefix are also received, but have no effect on subscription status.
XSUB socket
Same as SUB except that you subscribe by sending subscription messages to the socket. Subscription message is a byte 1 (for subscriptions) or byte 0 (for unsubscriptions) followed by the subscription body. Messages without a sub/unsub prefix may also be sent, but have no effect on subscription status.

[링크 : https://zeromq.org/socket-api/]

 

int zmq_device (int device, const void *frontend, const void *backend);
ZMQ_QUEUE starts a queue device
ZMQ_FORWARDER starts a forwarder device
ZMQ_STREAMER starts a streamer device

Queue device
ZMQ_QUEUE creates a shared queue that collects requests from a set of clients, and distributes these fairly among a set of services. Requests are fair-queued from frontend connections and load-balanced between backend connections. Replies automatically return to the client that made the original request.

This device is part of the request-reply pattern. The frontend speaks to clients and the backend speaks to services. You should use ZMQ_QUEUE with a ZMQ_XREP socket for the frontend and a ZMQ_XREQ socket for the backend. Other combinations are not documented.

Refer to zmq_socket(3) for a description of these socket types.

Forwarder device
ZMQ_FORWARDER collects messages from a set of publishers and forwards these to a set of subscribers. You will generally use this to bridge networks, e.g. read on TCP unicast and forward on multicast.

This device is part of the publish-subscribe pattern. The frontend speaks to publishers and the backend speaks to subscribers. You should use ZMQ_FORWARDER with a ZMQ_SUB socket for the frontend and a ZMQ_PUB socket for the backend. Other combinations are not documented.

Refer to zmq_socket(3) for a description of these socket types.

Streamer device
ZMQ_STREAMER collects tasks from a set of pushers and forwards these to a set of pullers. You will generally use this to bridge networks. Messages are fair-queued from pushers and load-balanced to pullers.

This device is part of the pipeline pattern. The frontend speaks to pushers and the backend speaks to pullers. You should use ZMQ_STREAMER with a ZMQ_PULL socket for the frontend and a ZMQ_PUSH socket for the backend. Other combinations are not documented.

Refer to zmq_socket(3) for a description of these socket types.

[링크 : http://api.zeromq.org/2-1:zmq-device]

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

ipc 성능 비교  (0) 2022.09.21
posix message queue  (0) 2022.09.21
파일 존재유무 확인하기  (0) 2022.02.11
select, poll, epoll  (0) 2021.11.02
Unhandled fault: external abort on non-linefetch  (0) 2021.05.25
Posted by 구차니
Linux API2022. 7. 14. 17:44

linux drm(direct render mode)에서 나오는 용어인데 관계가 어떻게 되는진 모르겠다.

[링크 : https://www.kernel.org/doc/html/v4.15/gpu/drm-kms.html]

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

syslog c api(?)  (0) 2021.02.17
libescp  (0) 2019.01.03
cups api  (0) 2018.12.20
system wait stdout  (0) 2018.10.22
ncurse  (0) 2015.04.27
Posted by 구차니
Linux API/v4l2022. 7. 13. 19:47

v4l2 디버깅을 위해서는 아래와 같이 설정해주면 dmesg에 출력되게 된다.

# echo 0x1f > /sys/class/video4linux/video1/dev_debug

[링크 : https://stackoverflow.com/questions/24330671/v4l2-kernel-space-debugging]

 

guvcview 유틸리티를 이용해서 테스트.

하단의 exposure, auto / (absolute) / Auto Priority 관련 설정을 바꿀때 나오는 값 확인

 

Exposure, Auto - Aperture Priority Mode

[ 1041.346246] video2: VIDIOC_DQEVENT: type=0x3, pending=0, sequence=13, id=10094850, timestamp=1040.623934215
[ 1041.346259] changes=0x3, type=1, value=3216, flags=0x10, minimum=39, maximum=10000, step=1, default_value=156
[ 1041.346272] video2: VIDIOC_DQEVENT: error -2: type=0x0, pending=0, sequence=0, id=0, timestamp=0.000000000

 

Exposure, Auto - Manual / 3216

[ 1128.312839] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0901/0x3
[ 1128.312866] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0901/0x3

 

Exposure (Absolute)

[  621.732496] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xe55
[  621.733321] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xe55
[  621.749803] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xe56
[  621.750586] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xe56
[  621.784790] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xcbf
[  621.785731] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xcbf
[  621.802333] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xcc0
[  621.803150] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xcc0
[  621.833353] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xc90
[  621.834204] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xc90
[  621.849972] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xc90
[  621.850772] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0902/0xc90

 

Exposure, Auto Priority (선택)

[ 1464.855961] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0903/0x1
[ 1464.855989] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0903/0x1

 

Exposure, Auto Priority (미선택)

[ 1519.669796] video2: VIDIOC_S_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0903/0x0
[ 1519.669856] video2: VIDIOC_G_EXT_CTRLS: which=0x9a0000, count=1, error_idx=0, request_fd=0, id/val=0x9a0903/0x0

 

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

v4l2-ctl 밝기 조절  (0) 2022.07.06
v4l2 timestamp  (0) 2017.04.19
uv4l  (0) 2015.09.13
리눅스에 웹캠 연결시 인식  (5) 2009.12.06
Posted by 구차니
Linux API/v4l2022. 7. 6. 15:21

 

$ v4l2-ctl

General/Common options:
  --all              display all information available
  -C, --get-ctrl=<ctrl>[,<ctrl>...]
                     get the value of the controls [VIDIOC_G_EXT_CTRLS]
  -c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]
                     set the value of the controls [VIDIOC_S_EXT_CTRLS]
  -D, --info         show driver info [VIDIOC_QUERYCAP]
  -d, --device=<dev> use device <dev> instead of /dev/video0
                     if <dev> starts with a digit, then /dev/video<dev> is used
  -e, --out-device=<dev> use device <dev> for output streams instead of the
                     default device as set with --device
                     if <dev> starts with a digit, then /dev/video<dev> is used
  -h, --help         display this help message
  --help-all         all options
  --help-io          input/output options
  --help-misc        miscellaneous options
  --help-overlay     overlay format options
  --help-sdr         SDR format options
  --help-selection   crop/selection options
  --help-stds        standards and other video timings options
  --help-streaming   streaming options
  --help-tuner       tuner/modulator options
  --help-vbi         VBI format options
  --help-vidcap      video capture format options
  --help-vidout      vidout output format options
  --help-edid        edid handling options
  -k, --concise      be more concise if possible.
  -l, --list-ctrls   display all controls and their values [VIDIOC_QUERYCTRL]
  -L, --list-ctrls-menus
                     display all controls and their menus [VIDIOC_QUERYMENU]
  -r, --subset=<ctrl>[,<offset>,<size>]+
                     the subset of the N-dimensional array to get/set for control <ctrl>,
                     for every dimension an (<offset>, <size>) tuple is given.
  -w, --wrapper      use the libv4l2 wrapper library.
  --list-devices     list all v4l devices
  --log-status       log the board status in the kernel log [VIDIOC_LOG_STATUS]
  --get-priority     query the current access priority [VIDIOC_G_PRIORITY]
  --set-priority=<prio>
                     set the new access priority [VIDIOC_S_PRIORITY]
                     <prio> is 1 (background), 2 (interactive) or 3 (record)
  --silent           only set the result code, do not print any messages
  --sleep=<secs>     sleep <secs>, call QUERYCAP and close the file handle
  --verbose          turn on verbose ioctl status reporting

 

$ v4l2-ctl -l -d /dev/video2
                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=95 step=1 default=5 value=5
                     saturation 0x00980902 (int)    : min=0 max=100 step=1 default=60 value=60
                            hue 0x00980903 (int)    : min=-2000 max=2000 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=100 max=300 step=1 default=100 value=100
                           gain 0x00980913 (int)    : min=1 max=8 step=1 default=1 value=1
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=2
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=1 max=7 step=1 default=2 value=2
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=1 value=1
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=1
              exposure_absolute 0x009a0902 (int)    : min=10 max=626 step=1 default=156 value=25

 

v4l2-ctl -d /dev/video2 -c exposure_absolute=70
v4l2-ctl -d /dev/video2 -c exposure_absolute=600

[링크 : https://thirdnsov.tistory.com/107]

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

v4l2 debug  (0) 2022.07.13
v4l2 timestamp  (0) 2017.04.19
uv4l  (0) 2015.09.13
리눅스에 웹캠 연결시 인식  (5) 2009.12.06
Posted by 구차니