<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lakisuru Semasinghe on Medium]]></title>
        <description><![CDATA[Stories by Lakisuru Semasinghe on Medium]]></description>
        <link>https://medium.com/@lakizuru?source=rss-8e438bc304d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0wgPJD_VMC24jBSc-K4mLA.jpeg</url>
            <title>Stories by Lakisuru Semasinghe on Medium</title>
            <link>https://medium.com/@lakizuru?source=rss-8e438bc304d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:00:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lakizuru/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Couldn’t Justify a $20 AI Subscription — So I Built This Setup Instead]]></title>
            <link>https://lakizuru.medium.com/i-couldnt-justify-a-20-ai-subscription-so-i-built-this-setup-instead-0ecc95e0c0fe?source=rss-8e438bc304d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ecc95e0c0fe</guid>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[github-copilot]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[developer-tools]]></category>
            <dc:creator><![CDATA[Lakisuru Semasinghe]]></dc:creator>
            <pubDate>Sat, 20 Jun 2026 20:52:09 GMT</pubDate>
            <atom:updated>2026-06-20T20:57:18.086Z</atom:updated>
            <content:encoded><![CDATA[<h3>I Couldn’t Justify a $20 AI Subscription — So I Built This Setup Instead</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9oTp04Uztf0SkobZ_ZsA5Q.png" /></figure><p>Maybe you’re a light AI user who feels that a monthly subscription is too expensive, yet you still find yourself exhausting the free-tier limits from time to time. If that sounds familiar, a pay-as-you-go approach might be the perfect alternative.</p><p>I’m a DevOps engineer who occasionally works on vibe-coding projects as a hobby. Most AI coding assistants, including GitHub Copilot, Cursor, and Antigravity, offer generous free quotas. However, I often found myself hitting those limits during weekend coding sessions. That usually led me to jump between different tools until I eventually ran out of free quota on all of them.</p><p>The obvious solution would have been to purchase a subscription plan from GitHub Copilot, Claude Code, or another provider. However, spending around $20 per month felt excessive because I only need these tools once or twice a month, even though I tend to use them heavily during those sessions.</p><p>After dealing with this for a while, I started looking for alternatives. With a few Gemini searches and recommendations from friends, I discovered that a prepaid pay-as-you-go setup was the best option.</p><p>This approach allows you to pay only for what you actually use. More importantly, prepaid billing provides peace of mind because there’s no risk of receiving an unexpectedly large bill due to excessive AI usage.</p><p>Solution was a bunch of good but cheap AI models with a good AI coding agent. Let me name them as follows, but obviously there can be even better combinations.</p><h3><strong>The Stack</strong></h3><p>My solution consisted of a combination of affordable AI models paired with a capable coding agent. While there are certainly many other valid combinations, the following setup has worked exceptionally well for me:</p><p><em>Models:</em></p><ul><li><em>DeepSeek V4 Flash</em></li><li><em>DeepSeek V4 Pro</em></li><li><em>Kimi K2.7 Code</em></li></ul><p><em>AI Coding Agent:</em></p><ul><li><em>Cline</em></li></ul><p>My choice of DeepSeek and Kimi was heavily influenced by my current project: a simple full-stack web application.</p><p>I found DeepSeek V4 to be one of the most cost-effective models for backend development tasks. Almost all my requests were sent to DeepSeek V4 Flash. However, it wasn’t as strong when working with visual elements and frontend-related tasks. To compensate for that, I also used Kimi K2.7 Code for frontend development. Kimi remains significantly cheaper than many popular premium models, although it is slightly more expensive than DeepSeek.</p><h3>OpenRouter</h3><p>Although Cline supports multiple API providers, managing separate accounts, API keys, and billing setups can quickly become inconvenient.</p><p>That’s where OpenRouter comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hVMY_edYBEqs_wrmJWg3mw.png" /><figcaption><a href="https://openrouter.ai/">OpenRouter</a></figcaption></figure><p>OpenRouter provides a unified API that gives access to hundreds of AI models from dozens of providers, including OpenAI, Google, Anthropic, DeepSeek, and many others.</p><p>Beyond simple access to models, OpenRouter offers a variety of controls and guardrails that help manage usage, costs, security, and privacy. You can carefully select which models and providers are available to your applications and enforce spending limits to avoid unnecessary expenses.</p><p>One feature I particularly appreciate is <strong>Auto Mode</strong> (openrouter/auto). Similar to GitHub Copilot and other AI coding assistants, it automatically routes requests to the most suitable model from a pool of available options. This helped me achieve good results without constantly paying premium prices for the most expensive models.</p><p>OpenRouter also provides a feature-rich dashboard where you can:</p><ul><li>Configure model access and routing</li><li>Monitor usage and spending</li><li>Set budgets and limits</li><li>Manage API keys</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sEP0gHPkjis9nvE1uWMmg.jpeg" /><figcaption>Activity Dashboard</figcaption></figure><p>The pricing model is what I find most appealing. You can top up your account with any amount and consume credits as needed. This acts as a second layer of protection against unexpected costs because your spending is limited by the available balance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnbnSAKbieeijKKzhT8J9g.png" /><figcaption>Guardrails</figcaption></figure><p>In addition, OpenRouter allows spending limits at both the API key and model level, with daily, weekly, and monthly controls.</p><p>One thing to keep in mind is that OpenRouter charges a $0.80 transaction fee for each top-up. Because of this, it’s generally more cost-effective to add a reasonable amount of credit at once rather than making frequent small top-ups.</p><p>While there are other alternatives, such as AWS Bedrock, I found OpenRouter to offer one of the easiest onboarding experiences with very competitive pricing.</p><h3>Cline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-rH8Hopa9lyHQIf8dWBKmA.png" /><figcaption><a href="https://cline.bot/">Cline — AI Coding, Open Source and Uncompromised</a></figcaption></figure><p>As someone who was already familiar with GitHub Copilot, Cline felt like the closest alternative.</p><p>I use Cline as a VS Code extension, just as I previously used GitHub Copilot, and the setup process was straightforward.</p><p>Before switching to Cline, I experimented with “<strong>Continue”</strong>. While “<strong>Continue” </strong>was capable of getting the job done, I found its user experience less polished compared to what GitHub Copilot offered.</p><p><a href="https://assets.int.cline.bot/assets/videos/optimized/understand-codebase-vs-code-studio.webm">https://assets.int.cline.bot/assets/videos/optimized/understand-codebase-vs-code-studio.webm</a></p><p>Cline is open source and integrates seamlessly with OpenRouter as well as many other model providers. Installation is as simple as adding the VSCode extension and configuring your API keys.</p><p>What I particularly like about Cline is its flexibility. It allows you to control permissions, model selection, and usage policies while still providing an experience that feels familiar to developers coming from GitHub Copilot.</p><p>For occasional AI-assisted development, this combination of OpenRouter, affordable models, and Cline has proven to be a practical and cost-effective alternative to maintaining a recurring subscription. If you feel the same, try this out and don’t forget to comment your experience below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ecc95e0c0fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microcontrollers for IoT]]></title>
            <link>https://medium.com/ms-club-of-sliit/microcontrollers-for-iot-d566fe7bf349?source=rss-8e438bc304d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d566fe7bf349</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[esp]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[microcontrollers]]></category>
            <dc:creator><![CDATA[Lakisuru Semasinghe]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 07:17:43 GMT</pubDate>
            <atom:updated>2022-04-21T10:29:27.695Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’ll be explaining the most widely used microcontrollers for IoT and which suit your requirements. If you are already familiar with IoT, you can directly proceed to the <strong>Microcontrollers </strong>section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1B3ZKlNPF0sJQXBngX2m5w.jpeg" /></figure><h3>What is IoT?</h3><p>IoT, or the Internet of Things, are devices that consist of sensors, actuators and the capability to process and communicate the data sent or received over the internet. Therefore, IoT devices need to be equipped with microprocessors and networking interfaces. With the development of technology, these components and technologies are now available in a wide variety to choose from when developing an IoT solution. But we must make the selection according to the requirements such as processing power, power efficiency, form factor, pin layout, technologies etc. This article will help you identify the widely used microcontrollers you can use for your IoT projects accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*o5YXdhLmO_2DfzdNVB54fQ.jpeg" /><figcaption>A conceptual IoT ecosystem</figcaption></figure><h3>Microcontrollers</h3><p>If you are familiar with computers, you may know about microprocessors. In general, we call them CPU or Central Processing Units. A microprocessor mainly consists of a Control Unit, an Arithmetic and Logic Unit (ALU) and some registers. Modern microprocessors are also equipped with cache memory to smooth data transfer between CPU and memory.<br>But microcontrollers are beyond microprocessors. Microcontrollers can be defined as a collection of one or more microprocessors, main memory, program memory, input/output peripherals etc. We can define a microcontroller as a System-On-Chip (SoC). As all of these components are contained collectively in a single chip, it is easier to handle in IoT development processes. However, microcontrollers’ collective attribute also ceases their possibility to tweak and upgrade their performances.</p><p><em>Most of the time, we see people misunderstand microcontrollers with development boards. The microcontroller is just a single component in a development board. Development boards are only used in entry-level prototyping.</em></p><p>Following are the widely used microcontrollers in the field of IoT. Each of them is different in its architecture, supported technologies, form factor etc.</p><ol><li><strong>Atmel AVR</strong></li></ol><p>Atmel is the manufacturer of the Atmel AVR microcontroller family (In 2016, Atmel was acquired by Microchip Technology). These were introduced in 1996, and mainly there are three series of microcontrollers as follows.</p><ol><li>ATmega32 series</li><li>ATmega16 series</li><li>AVR128 series</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*7VFH_jL-5ZqiL-My5xeyxg.jpeg" /><figcaption>ATmel Microcontrollers</figcaption></figure><p>These ATmega and AVR microcontrollers are known for their presence in popular development boards Arduino. Arduino Uno boards consist of ATmega 328p microcontrollers, while Arduino Mega 2560 boards consist of ATmega 2560 microcontrollers.</p><p><strong>2. Microchip PIC</strong></p><p>PIC (pronounced as “pick”; stands for Programmable Intelligent Computer) is a family of microcontrollers manufactured by Microchip Technology. PIC MCUs were firstly introduced in the 1970s. PIC MCUs were popular among developers before the rise of Arduino development boards. But still, PIC MCUs are heavily used in the large-scale production of IoT devices.</p><ol><li>PIC18 series (including PIC12 and PIC16)</li><li>PIC32 series</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45YGxcn9KCrjvmtA7AFh0w.jpeg" /><figcaption>PIC Microcontroller</figcaption></figure><p>These PIC microcontrollers were most popular with Microchip Curiosity Development Board and Ready-for Development boards.</p><p><strong>3. Espressif ESP</strong></p><p>ESP series microcontrollers are known for their Wi-Fi-enabled feature among IoT developers. ESPs are relatively new to the MCU market compared with the other MCUs. Below are the popular microcontroller series of ESP.</p><ol><li>ESP8266 series</li><li>ESP32 series</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*0gT9s18bx9sy9_F14Pat9A.jpeg" /><figcaption>ESP-WROOM-32 Microcontroller</figcaption></figure><p>ESP8266 is known for its presence on the NodeMCU development board. ESP32 series is the more developed successor of the ESP8266 series.</p><p>Out of all these microcontrollers, ESP series MCUs are more popular among IoT developers due to their Wi-Fi-enabled feature, which is not addressed in most other microcontrollers.</p><h3>Microcontroller Development Boards</h3><p>Microcontroller Development Boards, aka Single-board Microcontrollers, are Printed Circuit Boards that come with inbuilt microcontrollers. Other than the microcontroller, a power supply circuit, signal converters (Analog to Digital and Digital to Analog), system bus, serial ports (sometimes USB interface also) and I/O ports.<br>The most popular microcontroller boards are as follows. Rather than just microcontroller boards, Raspberry Pi and Arduino are considered IoT platforms, a standard where many IoT peripherals and their libraries are developed compatibly.</p><ul><li>Raspberry Pi — More suitable for heavy computational-oriented applications such as image processing. Built-in support for communication standards such as Wi-Fi and Bluetooth. Available in various models according to requirements.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*pAWFPjIq6oGTIroO6F2HAg.png" /><figcaption>Raspberry Pi Models</figcaption></figure><ul><li>Arduino — More suitable for lightweight compute applications such as sensor readings and minor actuators. No built-in support for communication standards. Available in various models according to requirements.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4ewArCt3NvHtdjDyuNZwg.png" /><figcaption>Arduino Models</figcaption></figure><ul><li>Espressif — More suitable for lightweight compute applications that require Wi-Fi. Much energy efficient and small in size and supports the Arduino platform. Available in various models according to requirements.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yY9hEoOi1g9JLEArjlSDrA.jpeg" /><figcaption>Espressif Models</figcaption></figure><p>Now you have an idea about what microcontrollers/development board suits your IoT solution. Feel free to clarify any doubts about this article’s facts by commenting below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d566fe7bf349" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ms-club-of-sliit/microcontrollers-for-iot-d566fe7bf349">Microcontrollers for IoT</a> was originally published in <a href="https://medium.com/ms-club-of-sliit">MS Club of SLIIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phonebook of the Internet: DNS in Simple Words!]]></title>
            <link>https://medium.com/sliit-foss/naming-the-computers-on-the-internet-dns-in-simple-words-1c74140e2b60?source=rss-8e438bc304d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c74140e2b60</guid>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[domain-names]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[domain-name-system]]></category>
            <dc:creator><![CDATA[Lakisuru Semasinghe]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 16:05:00 GMT</pubDate>
            <atom:updated>2022-03-31T01:18:00.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x23dJRsn5WFTaFpjLN26uQ.jpeg" /></figure><p>We all have been using the internet for years, maybe decades, and we all know that the internet is made up of many computers. But have you ever wondered how binary-oriented computers bring you your favorite websites within milliseconds by typing a name? This article will answer all of your problems related to internet name resolution.</p><p>If you are already familiar with some knowledge about internet such as URLs and IP addresses, you can directly proceed to the “What is DNS?” chapter below.</p><h3>Background</h3><p>As you already know, computers in any network identify themselves via unique IDs. Internet Protocol (IP) Address and Machine Access Code (MAC) Address are their primary IDs. Using these IDs, they can communicate with other computers. The IP address is a logical address assigned to a computer like a software configuration. But the MAC address is a physical address assigned to a computer when it is manufactured. So the computer cannot change its MAC address without changing the network interface card.</p><p>However, when there are multiple interconnected networks, there will be a requirement to route the data among these interconnected networks. Therefore, computers should be able to identify a computer in another remote-connected network and its network. IP addresses are used as the unique identifier in the above case to identify remotely connected computers uniquely.</p><p>According to the relevant IP version, IP addresses are either in decimal or hexadecimal numbers. An IPv4 address looks like 185.199.111.153, while an IPv6 address looks like 2606:50c0:8002::153. But we rarely deal with these numbers in our day-to-day life. Sometimes, you may haven’t noticed these numbers when using the internet. Instead of these so-called numbered IDs, we use IDs more likely a word, phrase or sentence when using the internet. Using such alphabetical IDs over numerical IDs has made it easier for people to read, write, type, and memorize these IDs. This facility is provided by an internet service called Domain Name Service (DNS).</p><p>Before going deep into DNS, let us focus on domain names. Domain name is a part of a URL as shown in the following diagram. In DNS resolution, DNS resolver considers the subdomain, domain name and top-level domain to deliver the respective IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*XQCtQ_dWyeV7EE3f8BiVvA.jpeg" /><figcaption>Structure of an URL.</figcaption></figure><h3>What is DNS?</h3><p>DNS is a system of hierarchical and decentralized servers serving DNS requests from DNS clients. It maps the alphanumeric (Not just alphanumeric, but also most of the Unicode characters) IDs known as Domain Names to the relevant numerical IDs known as IP addresses. This system consists of multiple components.</p><ol><li>Resolver</li><li>Root Nameserver</li><li>Top-Level-Domain Nameserver</li><li>Authoritative Nameserver</li></ol><p>These four components work together as a complete domain name system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*NuCO02GgHWLKu6TQWVA67g.jpeg" /><figcaption>DNS resolution process</figcaption></figure><p><strong>Step 1</strong>: The DNS service is used by the client applications such as web browsers and other internet-based software applications. These client applications send a DNS query to the resolver asking for the IP address for the specified domain name.</p><p>Resolver is the closest component to the end-user. It may reside on the same device as the client application or on a separate server. It also acts as a DNS cache accordingly. If this is a separately hosted server, it can act as a Recursive DNS server that fulfills the receiving queries by recursively following the results from higher DNS servers such as Root and TLD.</p><p><strong>Step 2</strong>: Root Nameservers are at the top of the DNS server hierarchy, which points out the IP addresses of TLD nameservers responsible for the requesting domain name.</p><p><strong>Step 3</strong>: Top-Level-Domain (TLD) nameservers are the 2nd level DNS servers in the hierarchy. Resolvers reach them with the reference from Root servers seeking the IP address of the Authoritative DNS server responsible for the requesting domain name.</p><p><strong>Step 4</strong>: At the last of the DNS process, there are Authoritative DNS servers. These reside in the domain and keep records about the subdomains of their domain. Once a TLD nameserver refers to an Authoritative nameserver’s IP address, the resolver reaches the respective Authoritative name server seeking the destination server’s IP address. Then only the resolver gets the expected destination IP address.</p><p>Higher nameservers such as Root, TLD and Authoritative nameservers are always iterative nameservers, which only respond to the requested query with its database rather than querying higher nameservers as recursive nameservers do.</p><p><strong>Step 5</strong>: Now the resolver answers the client application with the destination IP address for the requested domain name so that the client application can communicate with the expected destination server. Also, the resolver keeps track of these IP addresses and relevant domain names and acts as a DNS cache when the same domain name query is requested.</p><p><strong>Step 6:</strong> Finally, the client application can communicate with the expected destination server using the received IP address.</p><p>Now you know how the computers translate the URL you type on the address bar into a numeric IP address and reach the destination server. This article is only covering up to the DNS resolution process. Feel free to clarify any doubts about this article’s facts by commenting below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c74140e2b60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/naming-the-computers-on-the-internet-dns-in-simple-words-1c74140e2b60">Phonebook of the Internet: DNS in Simple Words!</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Rust can be used to Implement a better Operating System — Part 2]]></title>
            <link>https://medium.com/sliit-foss/how-rust-can-be-used-to-implement-a-better-operating-system-part-2-5b47fc336747?source=rss-8e438bc304d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b47fc336747</guid>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[os]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Lakisuru Semasinghe]]></dc:creator>
            <pubDate>Sun, 27 Feb 2022 14:49:06 GMT</pubDate>
            <atom:updated>2022-02-28T14:39:50.343Z</atom:updated>
            <content:encoded><![CDATA[<h3>How Rust can be used to Implement a better Operating System — Part 2</h3><p>This is the part 2 of the previous article on “How Rust can be used to Implement a better Operating System”. You can find the part 1 of this article via this <a href="https://medium.com/sliit-foss/how-rust-can-be-used-to-implement-a-better-operating-system-fe1d4327156c">link</a>.</p><h3>Rust Standard Library</h3><p>Rust’s library is amenable to OS development. It has two parts,<br>1. core library — lowest level aspects. It does not include allocation, threading, and other higher-level features<br>2. std library — built on top of the core. Contains allocation, threading, and other higher-level features</p><p>Binary is the machine code executed on hardware after being compiled or interpreted. Operating systems have a standard binary to support the application programs. Application software uses that standard binary from their host operating system by linking them to its binary instead of normal essential functions such as I/O. But operating system kernels do not use any linked binaries. Operating systems should be able to perform all alone. Also, the development of an operating system cannot rely on threads, files, heap memory, the network, random numbers, standard output, or any other features requiring OS abstractions or specific hardware. Therefore, developing an operating system kernel using Rust language makes it difficult to use the Rust standard (std) library.</p><p>Features of ‘std’ library are iterators, closures, pattern matching, option and result, string formatting, and of course, the ownership system. These features allow the programmer to reduce the programming workload on undefined behavior or memory safety.</p><h3>Multi-Tasking in Rust</h3><p>Operating systems use multitasking to perform many tasks at once. Almost all the modern operating systems are multitasking, supporting multiple processes to be processed at once. Technically, one CPU can only process one process at a time. Therefore, operating systems use one, two, or both of the following forms of multitasking.<br>1. Preemptive multitasking<br>2. Cooperative multitasking</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*80Qh3aO-WCggOmGE2WkZNw.jpeg" /><figcaption>Pre-emptive vs Cooperative multitasking</figcaption></figure><h4>Preemptive Multi-Tasking</h4><p>Preemptive multitasking uses interrupts to control the CPU to change the running process, which switches the CPU between processes in the middle of processing. This whole process is done by operating system forcefully using Interrupt Handler. The change of running processes is known as ‘Context Switching’. In context switching, all the details about the running process, including data in the CPU registers and Call Stack will be stored in memory. Each ‘thread’ will have a separate Call Stack. Assigning different Call Stacks for each Thread will minimize the overhead of context switching by reducing the need to store the same data repeatedly except the register contents. This form guarantees that each task will get a fair share of CPU time, though its memory usage is high.</p><h4>Cooperative Multi-tasking</h4><p>But in Cooperative multitasking, OS does not force the running process to give up the CPU. Instead, OS waits for the running process to voluntarily give up the CPU for the following process. This form is mainly used at the language level, such as in ‘coroutines,’ or ‘async/wait.’ Here, yields are declared by the programmer or compiler at some point of the program to give up the CPU voluntarily. Since the program is already programmed to pause at specified points, OS does not need to save the state of the process. OS only needs to store the output of the process until it resumes, which improves the performance of the whole computation process. Cooperative multitasking makes it also possible to use only a single call stack for all the processes by assigning different process states from time to time.</p><p>Rust provides 1st class support for cooperative multitasking in async/wait. Rust’s async/wait stores all the needed local variables in an auto-generated struct. Futures and Asynchronous programming make it async/wait possible.</p><h4>‘Future’</h4><p>‘Future’ represents a that might not be available yet but is required for the process soon. Instead of waiting for the process until the value is available, ‘future’ makes it possible to continue executing the process until that value is needed for the processes, which minimizes the waiting time of the running tasks by optimizing the process.</p><p>In Rust, ‘futures’ are represented by the ‘Future’ trait. ‘Poll’ method is used to check whether the needed value is available (‘Future’ becomes ready). Until the ‘Poll’ function notifies that the ‘Future’ is ready, the ‘Poll’ function must execute in a loop that unnecessarily causes the CPU to be busy.</p><p>The solution for that wait is using ‘Future Combinators.’ It keeps operations asynchronous. In combination with the async I/O interfaces, this can lead to a very high performance of the CPU. Since the Future Combinators are implemented as regular structs with trait implementations, the Rust compiler can excessively optimize them to achieve outstanding performance.</p><p>‘Future’ trait abstracts asynchronous tasks. Using async/wait, it is possible to work with futures like standard synchronous code. However, asynchronous functions return a future again, which must be added to an executor to run it.</p><p>‘await’ operations make the process pause at declared points when the compiler transforms the async/wait code into ‘state machines.’ The compiler only saves the minimal state for each pause point, resulting in minimum memory usage per task. To prevent containing ‘self-referential structs’ by the generated state machines, Rust uses the ‘Pin’ type to cease future movement within the memory once it is polled. It prevents pointer invalidation, which is a fundamental feature of Rust.</p><p>Therefore, developers can use Rust to develop a high-performance and memory-efficient operating system because of its features for multitasking capabilities.</p><h3>Testing</h3><p>Testing is instrumental in developing any program, even an operating system. It ensures that the developing program has the desired behavior. Testing is essential in creating an operating system to find bugs and avoid regressions.</p><p>Rust is designed to focus on the accurateness of its written programs. Rust includes support for writing automated software tests within the language. Even though it is not easy to guarantee the correctness of a code, Rust’s type system takes care of most of it, but it cannot ensure the code is 100% correct.</p><p>Rust supports custom test frameworks to execute test functions in the kernel. Rust has a built-in test framework that allows running unit tests without setting up anything. Since this is supported through Rust’s standard library, developers cannot use this to develop and test an operating system kernel.</p><p>However, Rust supports an unstable custom test framework with limited features, where the programmer can define the needed features and test the code. Programmer can use a serial monitor to get the test output.</p><p>Therefore, Rust’s limited testing capabilities can help build a modern operating system to some extent.</p><h3>Conclusion &amp; Summery</h3><p>By referring to all the facts mentioned above, Rust can be considered one of the best programming languages to build a modern operating system with high performance, high reliability, and high productivity. Developers can use Rust’s following features and components to implement such an OS.</p><ul><li>Memory-efficiency with heap allocation techniques</li><li>Thread concurrency with ownership system &amp; memory safety</li><li>Rust owned libraries</li><li>Multitasking capability with 1st class support for cooperative multitasking</li><li>Strong error-checking at compile time</li><li>Support for custom test frameworks</li></ul><h3>References</h3><ul><li>Writing Automated Tests — Official Website of MIT</li></ul><p><a href="http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/second-edition/ch11-00-testing.html">http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/second-edition/ch11-00-testing.html</a></p><p>• Rust Programming Language — Wikipedia</p><p><a href="https://en.wikipedia.org/wiki/Rust_(programming_language)">https://en.wikipedia.org/wiki/Rust_(programming_language)</a></p><p>• Rust Programming Language — Official Website</p><p><a href="https://www.rust-lang.org/">https://www.rust-lang.org/</a></p><ul><li>Writing an OS in Rust — Philip Opperman’s Blog</li></ul><p><a href="https://os.phil-opp.com/">https://os.phil-opp.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b47fc336747" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/how-rust-can-be-used-to-implement-a-better-operating-system-part-2-5b47fc336747">How Rust can be used to Implement a better Operating System — Part 2</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Rust can be used to Implement a better Operating System — Part 1]]></title>
            <link>https://medium.com/sliit-foss/how-rust-can-be-used-to-implement-a-better-operating-system-fe1d4327156c?source=rss-8e438bc304d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe1d4327156c</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[os]]></category>
            <dc:creator><![CDATA[Lakisuru Semasinghe]]></dc:creator>
            <pubDate>Fri, 25 Feb 2022 06:43:25 GMT</pubDate>
            <atom:updated>2022-02-27T16:35:04.607Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>How Rust can be used to Implement a better Operating System — Part 1</strong></h3><h3><strong>Rust Programming Language</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQNM4KTQlVGN0qT9-QU2gA.jpeg" /><figcaption>Rust Logo</figcaption></figure><p>Rust is a multi-paradigm programming language focused on performance and safety. Graydon Hoare at Mozilla Research initially designed it. It is implemented using itself. It has low-level control, which is found in C. Therefore, Rust is considered an upcoming alternative for C. It supports concurrent, functional, generic, imperative, and structured programming paradigms. Rust is primarily known for its safe concurrency, which allows its programs to run simultaneously without affecting each other.</p><p>Rust is intended for highly concurrent and highly safe systems. Syntactically, Rust is like C++. Also, programs coded using Rust are highly optimized and have better performance when compared to languages like Python because its compiler directly compiles the code into machine language. So no interpreter is sitting between the code and the hardware. Rust compiler does a strong compile-time check to catch all the potential errors that could arise at run-time, making it more reliable. Rust compiler is also implemented in Rust. It also allows skipping the safety checks in cases where necessary.</p><p>According to the Stack Overflow Developer Survey, Rust is considered the most loved programming language of developers and the 5th fastest growing programming language according to GitHub’s ‘State of the Octoverse.’ Rust is also known for its weightlessness. It makes running Rust programs on embedded systems with limited resources.</p><h3>Operating Systems</h3><p>Operating System is the software that works as the interface between the computer user and computer hardware. Therefore, to get the best out of the hardware to the user, a sound operating system is a must. A good operating system is sound in its reliability, security, and performance. A good programming language is essential to develop such an excellent operating system. Rust is a programming language with good performance, reliability, and productivity.</p><h3>Kernel</h3><p>The kernel is the central part of any computer operating system. The kernel controls the memory and CPU for processes by managing memory space and CPU time. Kernel sits between the application programs and hardware by acting as their interface. Therefore, computer user never directly interacts with the kernel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*nfs2NEiJm5Hg_3_EPSWgww.png" /><figcaption>Operating System Architecture</figcaption></figure><p>There are five types of kernels.<br>1. Micro kernel<br>2. Monolithic kernel<br>3. Hybrid kernel<br>4. Exo kernel<br>5. Nano kernel</p><p>Modern operating systems come with monolithic kernels, including many required device drivers, while micro kernels do not have any device drivers, just the basic functionality. In micro kernels, since the device drivers are not a part of the kernel, micro kernels are known for their memory efficiency but are challenging to implement operating systems.</p><p>To improve qualities such as performance, reliability, and productivity of an operating system, developers must implement its kernel with such qualities. Therefore, Rust can be used as the programming language to implement such a kernel because it is solely developed for such purposes.</p><h3>Build an OS using Rust</h3><p>Its kernel, which plays the most significant role, needs to build first to build an operating system. As mentioned above, the building kernel must be a good performing, memory-efficient and reliable kernel to make it used for an operating system with the same qualities. The programming language must provide all the required features to build such an operating system. Since Rust is still under development, various releases have been made public.</p><h4>Rust Nightly Release</h4><p>Rust’s ‘Nightly’ release is preferred to develop an operating system using Rust. It is a release of Rust language, alongside Stable and Beta releases of Rust. The nightly release has the experimental level features not available in Stable and Beta releases. It makes the reason for choosing Nightly over the other two releases to develop an operating system. Nightly is not an official release. It is the updated GitHub repository on every night by the Rust team. This release is frequently updated with new features and bug fixes even though it is the least stable release. These frequent updates make it possible for developers to use the latest features of Rust. However, these features are highly volatile and could be deprecated in the future.</p><h4>‘Cargo’ Package Manager</h4><p>Most powerful programming languages such as C C++ do not come with a dedicated universal package manager. But Rust comes with a package management tool called ‘Cargo.’ Cargo makes it possible for Rust to resolve dependencies, making the build process simpler automatically.</p><h3>Memory Efficiency in Rust</h3><p>Rust is known for its memory and thread management. Rust does not permit null pointers, dangling pointers, or data races in safe code. Rust core library provides an option type, which can test whether a pointer has some value or none. If any code segment does not obey those restrictions, such unsafe codes can be written using the ‘unsafe’ keyword provided by the language. Rust provides memory safety using a burrow checking system instead of an automated garbage collection method. Memory and resources are managed through a convention of ‘Resource Acquisition is Initialization’ (RAII), which is later described in this report.</p><p>There is a concept of references that do not involve run-time reference counting. It prevents dangling pointers and other forms of undefined behavior because Borrow Checker always verifies the pointers by compile time. These features of Rust make it possible to develop memory-efficient software, especially with a higher performance which is an essential factor for modern operating systems.</p><h4>Heap Allocation</h4><p>The kernel uses two types of variables to store data as follows.<br>1. Local variables<br>2. Static Variables</p><p><strong>Local variables</strong> store values that belong to the surrounding function. Its data will be gone when the function returns. Local variables are stored in the respective thread’s call stack. Call stack is a stack data structure that supports push and pop operations.</p><p><strong>Static variables</strong> belong to a specific process. These values are stored in a fixed memory location separate from the stack. They will be held there until the end of the process. Locations of the static variables are defined at the compile time.</p><p>Static variables are made to be immutable. Rust compiler enforces such a regulation to prevent the same static variable from being accessed by multiple threads simultaneously, which could cause a data race — modifying a static variable needs to be encapsulated in a ‘Mutex’. Mutex ensures there is only a single ‘&amp; mut’ reference to the variable at any given time.</p><p>Both of the above variable types have a significant drawback. The size of the variables is fixed at the compile time. Therefore, the variables cannot grow further with time and usage. To overcome that, ‘heap’ is used.</p><p><strong>Heap </strong>is a 3rd memory region supported by some programming languages. It supports dynamic memory allocation through functions ‘allocate’ and ‘deallocate’. This is not recommended to do manually. Therefore, an automated process is introduced as ‘Garbage collection’ found in Java and Python. Since it is also a running process, it causes a performance overhead.</p><p>Rust uses a different method to manage the heap. It uses ‘Borrow Checking’ approach to handle the heap. It is basically like borrowing in real life: Borrowing something with the promise of returning it at the end of use without destroying it. Rust’s Borrow Checker does the same as checking that all borrows end before an object is destroyed. By doing that, Rust’s compiler guarantees that there will be no use-after-free situations.</p><p>Rust’s ownership concept further checks the correctness of the dynamic memory operations on compile time as it abolishes the need for a garbage collector and improves performance. At the same time, programmers still have memory control, the same as C or C++ languages. Rust’s standard library provides abstraction types that call these functions implicitly.</p><h3>Ownership in Rust</h3><p>Ownership is Rust’s most unique feature out of other programming languages.</p><p>In Rust, there is an ownership system to improve data safety by limiting and controlling access to the data. All the values have a unique owner who has a defined scope. The scope of any value is the same as the scope of its owner.</p><p>However, values can be passed through different access modes such as<br>• Immutable reference → ‘&amp;T’<br>• Mutable reference → ‘&amp;mut T’<br>• Value → ‘T’</p><p>At all times, it’s possible to exist multiple immutable references or single mutable reference.</p><p>The Rust compiler enforces the ownership rules in compile-time and checks for the validity of the references, which is one of the top reasons to select Rust as the language to develop a reliable operating system. Rust’s ownership property also enforces memory safety, as mentioned earlier in this report.</p><h4>Thread Concurrency in Rust</h4><p>The interrupt controller needs to be programmed correctly to forward hardware interrupts to the CPU to build an operating system. These interrupts also need to be added to the interrupt descriptor table.</p><p>Hardware interrupt plays a considerable role when inputting from the keyboard. Instead of kernel monitoring the hardware periodically by polling, the kernel can use hardware interrupts to notify the CPU about any changes in hardware inputs. This act makes the kernel more efficient by allocating polling time to some other important task while interrupt controller taking care of that. Hardware interrupts are also faster than polling because hardware interrupts can notify the CPU almost any time, while polling will happen only periodically.</p><p>Since all the hardware cannot directly connect to the CPU, an intermediary known as ‘Interrupt Controller’ is used. These programmable interrupt handlers can categorize the interrupts into levels and act according to those priority levels.</p><p>However, hardware interrupts occur asynchronously while exceptions occur synchronously. Therefore, hardware interrupts are independent of running tasks, making it possible to interrupt any running process. It could cause the kernel any potential concurrency-related bugs. But Rust’s strict ownership model does not allow such bugs because it forbids a mutable global state.<br>It also ensures Rust is a suitable programming language to build a highly reliable modern operating system.</p><p>However, none of these prevents deadlocks, a logical lock done by threads themselves that never unlocks. It causes that thread to hang on indefinitely in the CPU. To avoid such deadlocks, interrupts are required to be disabled if the ‘Mutex’ is locked.</p><p><strong>To be continued… </strong>You can find the part 2 of this article via this <a href="https://lakizuru.medium.com/how-rust-can-be-used-to-implement-a-better-operating-system-part-2-5b47fc336747">link</a>.</p><h3>References</h3><ul><li>Writing Automated Tests — Official Website of MIT</li></ul><p><a href="http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/second-edition/ch11-00-testing.html">http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/second-edition/ch11-00-testing.html</a></p><p>• Rust Programming Language — Wikipedia</p><p><a href="https://en.wikipedia.org/wiki/Rust_(programming_language)">https://en.wikipedia.org/wiki/Rust_(programming_language)</a></p><p>• Rust Programming Language — Official Website</p><p><a href="https://www.rust-lang.org/">https://www.rust-lang.org/</a></p><ul><li>Writing an OS in Rust — Philip Opperman’s Blog</li></ul><p><a href="https://os.phil-opp.com/">https://os.phil-opp.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe1d4327156c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/how-rust-can-be-used-to-implement-a-better-operating-system-fe1d4327156c">How Rust can be used to Implement a better Operating System — Part 1</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>