星期三, 1月 20, 2021

MINDSHARE:如何“僅用QEMU進行模擬”

 https://www.thezdi.com/blog/2020/5/27/mindshare-how-to-just-emulate-it-with-qemu


Firmadyne

ARM-X

星期二, 1月 19, 2021

thread's signal mask

 thread's signal mask

copy from:

https://jyhshin.pixnet.net/blog/post/27826709


就跟傳統的 process 一樣,每個 thread 都有一個 signal mask,用來指定那些非同步 signal 會被 thread 處理,稱為 unblocked signals,那些 signal 不會被 thread 處理,稱為 blocked signals。根據 kernel 的設計,child process 中的第一個 thread 會繼承 parent process 中呼叫 fork 的 thread 的 signal mask,其它 thread 則會繼承呼叫 pthread_create 的 thread 的 signal mask。然後在 thread 再利用 pthread_sigmask 來調整 signal 是 blocked or unblocked。

當一個非同步產生的 signal 送達某個 process 時,它將由 process 中某個 thread 來處理,系統將會根據每個 thread 的 signal mask 來決定誰是選中的 thread 。如果有超過一個以上的 thread,它們的 signal mask 對 signal 來說都是 unblocked,系統將任意的幫你選一個。雖然你可以經由設定 signal mask 來影響系統選 thread 的過程,但無法直接指定某個 thread 來處理某個指定的 signal。

下面演示 pthread_sigmask 的範例,每隔二秒發出 SIGALRM 一次,由這個範例得到幾個結論。

  1. 預設的 signal mask = 0,也就是所有的 signal 都是 unblocked。
  2. signal 對 threads 的選擇都是以 thread 產生的順序為則準,所以每次都是第一個 threads 被選中。
  3. main 算是第一個 thread,如果沒有在 main 中使用 pthread_sigmask 來 block signal,則所有的 signal 都會由 main thread 來處理。
  4. main 中使用 pthread_sigmask 要注意,如果在 pthread_create 前使用,後面的 threads 會繼承變更後的 signal mask。
#include <pthread.h> #include <stdio.h> #include <time.h> #include <sys/signal.h> #include <sys/time.h> #define NUMTHREADS 3 void *thread_normal(void *parm) { pthread_t tid = pthread_self(); int rc; printf("Thread %u entered\n", tid); rc = sleep(15); if (rc != 0) { printf("Normal thread %u did not get expected results! rc=%d\n", tid, rc); pthread_exit(NULL); } printf("Normal thread %lu completed masked work\n", tid); pthread_exit(NULL); } void *thread_masked(void *parm) { pthread_t tid = pthread_self(); sigset_t mask; int rc; printf("Masked thread %lu entered\n", tid); sigfillset(&mask); rc = pthread_sigmask(SIG_BLOCK, &mask, NULL); if (rc != 0) { printf("%d, %s\n", rc, strerror(rc)); return NULL; } rc = sleep(15); if (rc != 0) { printf("Masked thread %lu did not get expected results! rc=%d \n", tid, rc); pthread_exit(NULL); } printf("Masked thread %lu completed masked work\n", tid); pthread_exit(NULL); } void sighand(int signo) { pthread_t tid = pthread_self(); printf("Thread %lu in signal handler, time=%d\n", tid, time(NULL)); return; } int main(int argc, char **argv) { int i, rc; sigset_t mask; struct itimerval itv; struct sigaction actions; pthread_t threads[NUMTHREADS]; pthread_t maskedthreads[NUMTHREADS]; printf("Enter Testcase - %s\n", argv[0]); printf("Set up the alarm handler for the process\n"); memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); actions.sa_flags = 0; actions.sa_handler = sighand; rc = sigaction(SIGALRM,&actions,NULL); printf("Create masked and unmasked threads\n"); for(i=0; i<NUMTHREADS; ++i) { rc = pthread_create(&threads[i], NULL, thread_normal, NULL); if (rc != 0) { printf("%d, %s\n", rc, strerror(rc)); return -1; } rc = pthread_create(&maskedthreads[i], NULL, thread_masked, NULL); if (rc != 0) { printf("%d, %s\n", rc, strerror(rc)); return -1; } } sigfillset(&mask); /* Mask all allowed signals */ rc = pthread_sigmask(SIG_BLOCK, &mask, NULL); if (rc != 0) { printf("%d, %s\n", rc, strerror(rc)); return -1; } printf("start time = %ld\n", time(NULL)); itv.it_interval.tv_sec = 2; itv.it_interval.tv_usec = 0; itv.it_value = itv.it_interval; setitimer(ITIMER_REAL, &itv, NULL); printf("Wait for masked and unmasked threads to complete\n"); for(i=0; i<NUMTHREADS; ++i) { rc = pthread_join(threads[i], NULL); rc = pthread_join(maskedthreads[i], NULL); } printf("Main completed\n"); return 0; }

執行結果

Enter Testcase - ./a.out Set up the alarm handler for the process Create masked and unmasked threads Thread 1082322112 entered Masked thread 1090710592 entered Thread 1099099072 entered Masked thread 1116941120 entered Thread 1125329600 entered Masked thread 1133718080 entered start time = 1242631196 Wait for masked and unmasked threads to complete Thread 1082322112 in signal handler, time=1242631198 Normal thread 1082322112 did not get expected results! rc=13 Thread 1099099072 in signal handler, time=1242631200 Normal thread 1099099072 did not get expected results! rc=11 Thread 1125329600 in signal handler, time=1242631202 Normal thread 1125329600 did not get expected results! rc=9 Masked thread 1090710592 completed masked work Masked thread 1116941120 completed masked work Masked thread 1133718080 completed masked work Main completed

星期二, 12月 22, 2020

Ubuntu 14 cmake issue

 https://github.com/jmwright/pythonocc_oce_setup/blob/c0e429337dd6b3b2f9a4fe7453529eb7b40ffc09/Ubuntu_14_04_OCE_PythonOCC_Setup.sh

星期五, 11月 13, 2020

Webrtc related



2. webrtc janus
3. WebRTC-streamer:

4. gst-rtsp-launch:
  1. Docker launch: https://github.com/steabert/gst-rtsp-launch
  2. use gst launch to be a rtsp server: gst-rtsp-launch
  3. GStreamer-1.8.1 rtsp server and client on ubuntu: procedure gst-plugins-good-1.8.1
  4. Gstreamer WebRTC


5. uv4l-server:
  1. http://www.linux-projects.org/documentation/uv4l-server/
  2. UV4L, two-way WebRTC Data Channels demo
  3. Playing RetropPie in a browser (on Android, PC...) with WebRTC
  4. !!! no source code !!!!

6. gst-rtsp-server:
  1. gst-rtsp-server
  2. Include RTSP and Onvif functions 
  3. docker run --rm -p 8554:8554 steabert/gst-rtsp-launch https://gitlab.freedesktop.org/gstreamer/gst-


7. rtsp Proxy / Relay

Project : Making and IP survillance system using gstreamer and Janus

Project : Making and IP survillance system using gstreamer and Janus https://telecom.altanai.com/tag/rtsp-server/



An audio test source
https://mathieuduponchelle.github.io/2018-02-01-Python-Elements.html

Fixing sluggish write performance of USB flash (thumb) drives

 

Fixing sluggish write performance of USB flash (thumb) drives

https://blog.oldcomputerjunk.net/2012/fixing-sluggish-write-performance-of-usb-flash-thumb-drives/

Fixing sluggish write performance of USB flash (thumb) drives

This has been noted in various places around the web but in practice what I did seems to be a combination of various writings so I have documented my own experiences here.

Background

I recently acquired a (yet another) USB flash drive, this a 16 GB “Dolphin” brand. The actual device reports as “048d:1165 Integrated Technology Express, Inc.” when interrogated using lsusb. I am using it to transfer transcoded Kaffeine PVR recordings from my PC to the set top box in the lounge for more comfortable watching.

On first use, however, it took what seemed like forever to transfer a 250MB AVI file, over USB2, and looking at the GKrellM chart the write data rate appeared to be a very poor 350 kB/sec. So it seemed yet again, I needed to optimise a USB disk before it was adequate for use.

In theory, to simplify things to one sentence, flash disk (and in particular, modern SSD) should be faster than spinning disks, as access is a true physical random access operation, without having to wait for the heads to be in the right spot. However this is invalidated due the blocky nature of flash disk writes. The actual reason for the poor write speed is that the default partition starts at the 63rd sector (byte 32256) on the disk, and USB flash drives, SD cards, etc. are designed to write data in chunks of say 128kB at a time. Even if you only write one sector, the entire 128kB (or 256 sectors) must be (re-read first and) written. So when a partition is not aligned on a 128kB boundary, more writes than otherwise necessary are required, slowing performance. USB flash drives generally employ FAT32 so they are usable on the widest variety of devices (including set top boxes) and the general experience of FAT32 is that write performance is severely affected if the partition alignment does not match the flash write size, for both the partition and the FAT master table itself.

Procedure

The procedure I follow for doing fixing misaligned flash drives is:

1. Find a Linux computer, or reboot using a live Linux distribution such as [SysRescueCD](http://www.sysresccd.org/SystemRescueCd_Homepage)

2. Destroy the existing partition.


3. Recreate a single partition, ensuring it starts at the 256th sector (byte 131072, or 128kB)

    
4. Format the partition to FAT32. with the following non default options:

  * override the default sectors per cluster to ensure clusters are aligned.  This comes at some expense of apparent usable space, but the performance gain for writing large files such as video files is more than worth it.
  * Adjust the "reserved" sectors so that the FAT table itself is aligned to 128kB.

Detailed Steps

The following command sequence will accomplish this under Linux. This assumes your drive is at /dev/sdd, this will vary depending on what other disks you have.

1. Run GNU fdisk with units in sector mode not cylinder mode.  Then print the existing partition table (enter _p_ when prompted.  Below you can see the start sector of the existing partition is at sector 63.  Note this is also a primary partition.  This is typical of USB flash disks you might purchase at the local supermarket... ```bash fdisk -u /dev/sdd``` ``` GNU Fdisk 1.2.4 Copyright (C) 1998 - 2006 Free Software Foundation, Inc. This program is free software, covered by the GNU General Public License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Using /dev/sdd Command (m for help): p

Disk /dev/sdd: 16 GB, 16162675200 bytes 255 heads, 63 sectors/track, 1965 cylinders, total 31567725 sectors Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System /dev/sdd1 63 31570943 15791863 c FAT32 LBA Warning: Partition 1 does not end on cylinder boundary.
Command (m for help):




    2. Delete the partition:

Command (m for help): d Partition number (1-1): 1
Command (m for help): p

Disk /dev/sdd: 16 GB, 16162675200 bytes 255 heads, 63 sectors/track, 1965 cylinders, total 31567725 sectors Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System Command (m for help):




    3. Recreate the partition, aligned at sector 256 (131072 bytes), and set the type back to FAT32 LBA (in this case matching what previously existed) (type 'c', or 0x0c, i.e. FAT32 LBA).  Use of FAT32 LBA allows use to start the filesystem on an arbitrary sector bearing no relationship to legacy cylinders, etc.  The final sector depends on the disk size.

Command (m for help): n
Partition type
e extended p primary partition (1-4) p First sector (default 63s): 256s
Last sector or +size or +sizeMB or +sizeKB (default 31567724s):
Command (m for help): t
Partition number (1-1): 1
Hex code (type L to list codes): c
Changed type of partition 1 to c (FAT32 LBA) Command (m for help): p

Disk /dev/sdd: 16 GB, 16162675200 bytes 255 heads, 63 sectors/track, 1965 cylinders, total 31567725 sectors Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System /dev/sdd1 256 31567724 15783831 c FAT32 LBA Command (m for help):




    4. Save changes:

Command (m for help): w
Information: Don’t forget to update /etc/fstab, if necessary.

Writing all changes to /dev/sdd.




    5. Format the partition, setting the number of reserved sectors so that the FAT table remains aligned at a 128kB boundary.  Assuming sectors per cluster, s=128 (65536 bytes), and our partition length of 31567469 sectors, we want the first fat to start at the 256th sector within the partition (which is OK as the partition itself is aligned.)  For some sizes of flash disk, this can be an iterative process, but generally setting the number of reserved sectors to 256 will achieve what we want.
```sh
mkfs.vfat -v -F 32 -n label -s 128 -R 256 /dev/sdd1
mkfs.vfat 3.0.9 (31 Jan 2010)
/dev/sdi1 has 255 heads and 63 sectors per track,
logical sector size is 512,
using 0xf8 media descriptor, with 31567468 sectors;
file system has 2 32-bit FATs and 128 sectors per cluster.
FAT size is 2048 sectors, and provides 246586 clusters.
There are 256 reserved sectors.
Volume ID is 3bd81e55, volume label fatflash   

6. This is the most important step - verify that the chosen number of reserved sectors has resulted in an aligned FAT table and aligned data area. ```sh fsck.vfat /dev/sdd1 ``` ``` fsck from util-linux-ng 2.17.2 dosfsck 3.0.9 (31 Jan 2010) dosfsck 3.0.9, 31 Jan 2010, FAT32, LFN Checking we can access the last sector of the filesystem Boot sector contents: System ID "mkdosfs" Media byte 0xf8 (hard disk)
   512 bytes per logical sector
 65536 bytes per cluster
   256 reserved sectors First FAT starts at byte 131072 (sector 256)
     2 FATs, 32 bit entries    1048576 bytes per FAT (= 2048 sectors) Root directory start at cluster 2 (arbitrary size) Data area starts at byte 2228224 (sector 4352)
246586 data clusters (16160260096 bytes) 63 sectors/track, 255 heads
     0 hidden sectors   31567468 sectors total Checking for unused clusters. Checking free cluster summary. /dev/sdd1: 1 files, 1/246586 clusters ``` The important figure here, is the data area sector - it must be an integer multiple of 256, and 256 x 17 == 4362 in this example.



7. Test the result.  I copied a 256 MB file onto the drive, and GKrellM is now reporting ~2.5MB/sec.  More importantly, it finished in approx. one eighth of the time compared to before reformatting.

The improved write performance should be just as noticeable from Windows.

posted in 

subscribe via RSS