顯示具有 ARM 標籤的文章。 顯示所有文章
顯示具有 ARM 標籤的文章。 顯示所有文章

2021年1月7日 星期四

Linux 用 bluetoothctl 連接 藍牙裝置

啟用 Bluetoothctl 管理

# bluetoothctl

列示 bluetooth dungle 裝置 mac

[bluetooth]# list
Controller [local mac address]

指定控制的藍牙裝置

[bluetooth]# select [local mac address]

啟用藍牙裝置

[bluetooth]# power on

打開掃描功能

[bluetooth]# scan on

打開 agent

[bluetooth]# agent on

畫面這時會閃現裝置掃描到的可連接藍牙裝置

信任要連接的裝置mac

[bluetooth]# trust [BT mac address]

與連接裝置做 pair 動作

[bluetooth]# pair [BT mac address]

(需手動認證的裝置的話這邊需要輸入畫面顯示的 PIN code.)

連結裝置

[bluetooth]# connect [BT mac address]

搞定收工

[bluetooth]# exit 

資料來源: http://oniloki.blogspot.com/2014/07/bluetoothctl.html

2020年12月22日 星期二

Linux記憶體壓力測試-memtester工具

最近要測試一臺機器的整體效能情況,就在google搜尋一番,發現這個一個小工具,說是可以進行記憶體的壓力測試,Memtester主要是捕獲記憶體錯誤和一直處於很高或者很低的壞位, 其測試的主要專案有隨機值,異或比較,減法,乘法,除法,與或運算等等. 通過給定測試記憶體的大小和次數, 可以對系統現有的記憶體進行上面專案的測試。

     1 下載

wget http://pyropus.ca/software/memtester/old-versions/memtester-4.2.2.tar.gz
     2 安裝
tar zxvf memtester-4.2.2.tar.gz cd memtester-4.2.2 make && make install
     3  引數介紹

         memtester [-p PHYSADDR] <MEMORY> [ITERATIONS]

         MEMORY 申請測試記憶體的數量,單位預設是megabytes(兆),也可以是B K M G

         ITERATIONS 測試的次數,預設是無限

     4 開始測試,申請10M記憶體,測試一次,如下圖:

       5 試用心得

          主要想對記憶體進行壓力測試,以上只是試用,可以申請大記憶體,放入後臺無限測試

          nohup memtester 2G  > /tmp/memtest.log &

編譯:
1. 修改conf-cc , conf-ld 檔案中的cc為
   arm-hisivxxx-linux-gcc
2. make
使用:
  # malloc 1M 測試2次
  memtester 1M 2
  # 測實體地址0x88000000~0x8fffffff 測試2次
memtester -p 0x88000000 128M 2

./memtester -p 0xc0000000 1M 1 > ./memtest.log & 


資料來源: https://www.itread01.com/content/1546701868.html

How to stress test your CPU on Linux

There are many reasons why you may want to stress test the CPU on your Linux system. You may want to see how your operating system and hardware perform when you are at full CPU utilization in order to spot software bugs or hardware failures. Alternatively, you may want to generate a lot of heat fast to troubleshoot a temperature-related issue with your machine; maximizing the CPU utilization will do that. Whatever the reason, there is a fast and easy way to accomplish that goal.

In this tutorial you will learn:

  • How to perform stress tests on the CPU using the yes stress test
  • How to perform stress tests on the CPU using the stress command
  • How to perform stress tests on the CPU using the s-tui command
How to stress test your CPU on Linux
How to stress test your CPU on Linux

Software requirements and conventions used

Software Requirements and Linux Command Line Conventions
CategoryRequirements, Conventions or Software Version Used
SystemDistribution-independent
Softwareyes, getconf, seq, bash, stress, s-tui
OtherNo root privileges required for the yes stress test. Privileged access to your Linux system as root or via the sudo command may be required to install other stress test packages.
Conventions# - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Usage Scenario

The yes stress test detailed in this article can be very useful for troubleshooting purposes. Frequently, intermittent issues do not become reproducible until the system is under heavy load, sometimes for a prolonged period of time. You may find yourself in a situation where your machine, or one you are maintaining for a user, is experiencing unexpected shutdowns, kernel panics or other intermittent issues. In this situation you may want to attempt to reproduce the issue. In that case, you could run the following command to stress test the processor, making the issue more likely to occur, and therefore observable to you.

After you have taken steps to remedy the situation such as uninstalling software, reinstalling software including the operating system or replacing hardware components you could run the command again to determine whether or not it has resolved the issue.

Yes Stress Test

This one-liner will create a yes process to run on each processor core of the machine. yes prints the letter y repeatedly until it is killed. On an idle system, each yes process will utilize 100% of a CPU core. If the processor supports hyper-threading and it is enabled then it will create twice as many processes, as this is necessary to fully maximize the CPU utilization.

The benefit to this approach is that it requires only standard utilities that come out of the box on GNU/Linux systems, so no installation of additional programs or libraries are needed. Additionally, it does not require root privileges to run. To begin, enter the following command into your terminal.

$ for i in $(seq $(getconf _NPROCESSORS_ONLN)); do yes > /dev/null & done


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Let’s break down exactly what this one-liner is doing. getconf _NPROCESSORS_ONLN obtains the number of CPU cores; including virtual ones for processors with hyper-threading. Running the command within $() places it’s output as an argument to the seq command.

seq $(getconf _NPROCESSORS_ONLN) prints a sequence of numbers from 1 up to the amount of virtual CPU cores present in the system. Running that within $() allows that sequence of numbers to be used in our bash for loop.

Finally, the for loop itself, for i in $(seq $(getconf _NPROCESSORS_ONLN)); do yes > /dev/null & done takes the sequence of numbers from 1 to the amount of virtual cores and for each one of them starts a yes process and redirects it’s output to /dev/null.

htop after running the command
htop after running the command

When running this command it is advisable to use tophtop or some other program to monitor the CPU utilization in order to verify that it is reaching 100%. We previously published an article on how to check and monitor cpu utilization on linux.

When you want to stop the yes processes and return to normal CPU utilization, simply enter the following into your terminal.

$ killall yes

Other CPU Stress Test Methods

Stress

Stress is a simple workload generator that imposes a configurable amount of stress on the system. In addition to being able to stress test the CPU, it is also able to perform memory, I/O and disk stress on a system.

On Arch Linux and Manjaro it can be installed with the following command.

$ pacman -S stress

On Debian, Ubuntu and Mint it can be installed with the following command.

$ sudo apt install stress

On RHEL based distros it can be installed with the following command after enabling the Extra Packages for Enterprise Linux (EPEL) Repository

$ sudo yum install stress

To perform a stress test with stress, simply enter the following command where the number used in --cpu is the amount of threads to start. To fully stress the CPU, this should be the total number of CPU cores or double that if the CPU supports hyper-threading. You can obtain the appropriate number to use by entering getconf _NPROCESSORS_ONLN. In our example we are performing the stress test on a quad core i7 which supports hyper-threading, so we use 8.

$ stress --cpu 8


S-tui

s-tui is a text user interface front-end for the stress command. In addition to running the stress test performed by stresss-tui also monitors CPU temperature, frequency, power and utilization while displaying graphs corresponding to each value in the terminal. s-tui can be installed across all distributions by using pip. To do so, enter the following command.

$ pip install s-tui --user

To run the stress test enter the s-tui command into your terminal, then press the down arrow (or j key) and press enter to switch from monitor mode to stress mode. You will see a graphical representation similar to the following screenshot.

s-tui
s-tui

Conclusion

In this article we saw how to maximize the CPU utilization on your Linux system using the yes command within a bash for loop to perform a “yes stress test”. We then broke down each part of the command to see exactly what it was doing and how it worked. We discussed monitoring the CPU utilization to verify that it is reaching 100%, then we saw how to install and use stress and s-tui to perform a CPU stress test.

The benefit to using s-tui is that you are able to monitor performance without using any additional software. The benefit to using the “yes stress test” is that you are able to perform the stress test without having to install any additional software. If you are looking to run more extensive stress tests and benchmarking on your Linux system then our article on how to benchmark your linux system has you covered. 

資料來源: https://www.tecmint.com/linux-cpu-load-stress-test-with-stress-ng-tool/

2020年12月18日 星期五

Yocto WiFi configuration for automatic connection at boot

Objective: This writeup will cover WiFi configuration on Raspberry Pi using the Yocto tool. The goal is to have an automatic WiFi connection on boot-up

Recommended prerequisite articles to read:

  1. Custom Raspberry Pi Image Build with Yocto

In the previous article, we built a console-only image for the Raspberry Pi 4. For such a headless set up, we need a smooth way to interact with the device. One of the most convenient way is the use of the SSH protocol that can allow us to remotely access the raspberry pi and even transfer files to it via scp. However, to use these tools the board and the host machine need to be connected in a way such as being in the same local network or connected to the internet. Hence to connect the Pi to the internet, we need to enable the WiFi.

We don’t want to be manually configuring the WiFi every time a reboot occurs. At the time being, we can assign a static IP address to our board since this is for in-house development. We will also hard code the router/network SSID and our password. All these can be performed after bootup but we want to have all the network configurations performed automatically at boot up.

1. Configure SSID and passphrase

Edit the wpa_supplicant.conf-sane in the following path … /meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/wpa_supplicant.conf-sane

ctrl_interface = /var/run/wpa_supplicant
ctrl_interface_group = 0
update_config = 1
 
Network = {
               ssid = "SSID"
               psk = "PASSWD"
}

2 . Script to initialize the wpa_supplicant and configure WiFi at boot up

Create a custom script “setup-wifi.sh” at the following path …/meta/recipes-core/initscripts/initscripts-1.0/setup-wifi.sh

#!/bin/sh
ifconfig wlan0 10.233.174.16   #Set the static IP address, should be unique
wpa_passphrase SSID  PASSWD> /etc/wpa_supplicant.conf
route add default gw 10.233.174.254  #Router IP address
wpa_supplicant -B -i   wlan0    -c    /etc/wpa_supplicant.conf
echo “nameserver 8.8.8.8” >> /etc/resolv.conf
echo “nameserver 10.233.174.254” >> /etc/resolv.conf
: exit 0

3. Edit initscript recipe to enable WiFi configuration at boot up

Edit the initscript bitbake recipe at … /meta/recipes-core/initscripts/initscripts-1.0.bb that incorporates the “setup-wifi.sh” and installs it in /etc/initscripts directory after build.

SRC_URI = "
file://setup-wifi.sh \
"
do_install () {
install -m 0755    ${WORKDIR}/setup-wifi.sh     ${D}${sysconfdir}/init.d
  
update-rc.d -r ${D} setup-wifi.sh start 99 2 3 4 5 .
}
  
MASKED_SCRIPTS = " \
setup-wifi \
"

SSH

With the above configurations, rebuild the core-image as explained in the previous article. On bootup, you can test the WiFi configuration by issuing the commands:

ifconfig            //should show the IP address of the Pi as hard coded in the Yocto image
ping google.com        //shows that the DNS server(s) hardcoded are working

With the above network configurations, we can access the board remotely via ssh and transfer files via scp from a Linux machine.

On the Linux machine, we enter the IP address we assigned to the board as below:

ssh root@10.233.174.16

This opens a terminal console of the board remotely and we can access all the files remotely.

 

資料來源: https://reiwaembedded.com/raspberry-pi-yocto-wifi-configuration-for-automatic-connection-at-boot/