Category: Uncategorised

  • bash 技巧 note

    算是写给自己看也方便自己记住。

    最近运行python程序的时候学会了一个用法 -m, 具体的来说就是可以直接从当前root调用文件夹内的程序而不用担心相对关系。比如 在文件结构如下的时候

    +Root ———————+
    +–Data ——————-+
    +—-32_1.npy————-+
    +–Output—————–+
    +–Scripts—————–+
    +—- compare_data.py—+
    + main.py——————+

    可以用 python -m Root.Scripts.compare_data 来调用程序。在用argparser设置了参数以后,参数的调用也可以直接从子文件夹开始就可以了,比如–data-dir Data/32_1.npy

    在调用bash命令的时候可以活用 > 来调节输出,比如

    python s.py 2>&1 >output.txt

    python s.py >output.txt 2>&1

    之间,前者将stderr映射到了terminal,但是只有stdout输出到了output.txt,而后者先将stdout映射到了output.txt,然后将stderr也映射到了同一个地址,导致的后果就是terminal里什么都没有,但是所有的结果都输出到了output.txt。bash里的小逻辑还真是挺有趣的。

    这倒让我想起来在hpc上面交任务的时候,有时候要批量处理,我会做

    for i in {1..15}; do cd a_$i; sbatch main.py; cd ..; done; end;

    现在想起来,当时的代码要是写成现在可以指定输出文件夹的方式,跑起来就舒服多了,也不需要一直cd进文件夹去,哈!

  • 某种和解

    23年的草稿。忘记放出来了。

    最近粗略地通过手机读了黑塞的《悉达多》。严谨地说读起来比《荒原狼》要易读得多。与之前略读的《在轮下》不分上下。第一感觉是后者对教育的控诉也好(主人公成为教育制度的牺牲品,因为不合时宜而被社会和时代的轮毂碾过),又或是前者佛陀的化身悉达多历经生活在自我中与佛性本身合而为一也好,都觉得未免过度浅显直白了。作为诺奖作者的作品,本觉得应该有些更深层的意涵尚未品味出来。

    不到一定的年龄确实难以想象这种面临着未来“可能性”急剧减少而自己本身从各种意义上都不断下滑的状态。比身边的人更有比较优势的人往往会以自身能力跻身更高层次的社会功能

  • Kernel Panic on older Macbooks – A permanent cure

    It took some time I know, since I last managed to resurrect the old Macbook 2013 from a completely unusable state 3 years ago. It was an antedote to speeding fan, to a completely paniced kernel service (that goes up to more than 200% usage for the minimal amount of applications).

    The kernel panic happened essentially due to the system detecting a sensor signal that suggests there is overheating in the CPU. In order to prevent this, and protect the machine from overheating, it tries to throttle the CPU power for as much as possible till the sensor returns to normal. It does this, apparently via two ways, first of which is an IOcontrol module, which the last fix takes care of. Upon the fix, my CPU usage for light uses (e.g. browsing news website on chrome) consumed only 50-70% of CPU power, and the Mac was useable as a note-taking device. But that was not quite enough. The Macbook, despite being old, was a lot more power than that (It has three cores each in theory capable of being clocked to 2.9GHz). As it turns out, the core CPU was still being throttled physically via hardware limitation – the voltage supply to the CPU is capped at around 0.7241 volts, and as a result, CPU clock-speed capped at 0.8GHz (less than a third of the maximum capacity – and that explains almost 50% CPU usage for merely opening a page in chrome!)

    I came upon this tool that could detect the core frequency, and upon some searches (and browsing through the Q&A sections), another tool being used by people with powerful Macs to clock-down their fast CPUs in order to gain better battery performance has surfaced as the ideal tool to get the CPU back to its normal working speed. Here is a quick walk through of how:

    We need a tool called Voltageshift. You might be tempted to build the tool from source just to err on the safe side. Been there, did not succeed. It seems that the support for older versions of XCode was no longer good enough for that build. I chose to download the built version supplied by the author instead.

    in order to use the tool, it needs to be uplifted in list of kext files, using the command similar to below. Replacing the directory to VoltageShift to wherever the downloaded/build kext file is saved

    sudo chown -R root:wheel ./VoltageShift.kext

    It is easy to run the following code to verify the installation:

    ./voltageshift.info

    This should provide a summary of the CPU core, which could look something like this:

    ------------------------------------------------------
       VoltageShift Info Tool
    ------------------------------------------------------
    CPU voltage offset: 0mv
    GPU voltage offset: 0mv
    CPU Cache voltage offset: 0mv
    System Agency offset: 0mv
    Analogy I/O: 0mv
    Digital I/O: 0mv
    CPU BaseFreq: 2400, CPU MaxFreq(1/2/4): 2900/2900/2900 (mhz)OC_Locked  PL1: 100W PL2: 125W 
    CPU Freq: 0.8ghz, Voltage: 0.7241v, Power:pkg 9.40w /core 2.06w,Temp: 43 c

    Use the following piece of code to force CPU voltage back to normal (disclaimer: use this at own risk, it will definitely void warranty; you shouldn’t do it if you are not sure)

    ./voltageshift write 0x1FC 0x04005e

    In my case, this usually forces the CPU to go back to CPU Freq of 2.4 GHz if something demanding is already running. Notice the immediate speeding up of CPU back to how it used to be (which seemed likea long distant memory).

    P.s. One thing to note, from my own experience, and from feedback in the forum, the override seems to be discarded each time Macbook wakes up from a sleep cycle. So it needs to be applied again. It is minimal hassle considering the speed boost that I get back. I also made a shell script to quickly run it each time the Macbook sleeps. Although not fully automated, it is definitely is an acceptable solution for the end-result.

    P.p.s Seems that upon a few refreshes that Mac will throttle the CPU regardless of fix above, and this seems to be done on OS level. Some posts online suggests that we in the previous step that we removed the IOSystem kext, we will also need to remove another kext AppleSMCLMU. Do something like

    mv AppleSMCLMU.kext /Volume/Macintosh \HD/Kextbackup/

    In this case I simply used rm -r to remove the file… Will see whether this renders the Mac completely un-useable or is a magic fix 🙂

  • 读书

    2023年从某些方面感觉到了自己的变化。一则托实体中文书和微信读书的福重新找到了阅读的状态。间歇着去读中文和英文的小说,反而让阅读的感受更加舒缓,没有那么急功近利的感觉了。毕竟中文阅读还是在使用母语,更自然些。另一方面而言,阅读中文更容易一目十行而忽略掉细节性的内容,所以更多是读一些简单的放松的作品(例如伊坂幸太郎这样信息量较低的小说),或者一些优美的经典作品。

    时间近凌晨一点便不展开细说。最近读完了詹姆斯·乔伊斯的《都柏林人》。之前只是耳闻他以《尤利西斯》的晦涩难懂而闻名,没想到这本书极度细腻深沉。难想象这是一位年轻人的处女座。其中最后一篇给人印象深刻,尤其是结尾,无论是中文还是英文,都是我所读过作品里最震撼人心之一。甚至媲美《了不起的盖茨比》里那句著名的

    And so we beat on, boats against the current, borne back ceaselessly into the past.

    《死者》这篇文章是《都柏林人》的最后一篇,一般被称为是詹姆斯·乔伊斯在尤利西斯以前集大成的一篇短篇小说。它经常被引用的结尾是这样的

    雪落在阴晦的中部平原的每一片土地上,落在没有树木的山丘上,轻轻地落在艾伦沼地上,再往西,轻轻地落进山农河面汹涌澎湃的黑浪之中。他也落在山丘上孤零零的教堂墓地的每一个角落,迈克尔·福瑞就埋葬在那里。它飘落下来,厚厚的堆积在歪斜的十字架和墓碑上,堆积在小门一根根栅栏的尖顶上,堆积在光秃秃的荆棘丛上。他听着雪花隐隐约约地飘落,慢慢地睡着了,雪花穿过宇宙轻轻地落下,就像他们的结局似的,落到所有生者和死者身上。

    Yes, the newspapers were right: snow was general all over Ireland. It was falling softly upon the Bog of Allen and, further westwards, softly falling into the dark mutinous Shannon waves. It was falling too upon every part of the lonely churchyard where Michael Furey lay buried. It lay thickly drifted on the crooked crosses and headstones, on the spears of the little gate, on the barren thorns. His soul swooned slowly as he heard the snow falling faintly through the universe and faintly falling, like the descent of their last end, upon all the living and the dead.

    这段文字里有种宏大的投射到每一个人身上的力量。只是不声不响轻轻飘落的雪花一视同仁地覆盖这个世界的所有物事,沉重得让人感到窒息。