Tuesday, November 2, 2010

Vivekananda Quotes on Education and Society

EDUCATION AND SOCIETY

Complete Works of Swami Vivekananda: http://www.advaitaashrama.org/cw/


    Education is the manifestation of the perfection already in man. (IV. 358)

    What is education? Is it book-learning? No. Is it diverse knowledge? Not even that. The training by which the current and expression of will are brought under control and become fruitful is called education. (IV. 490)

    To me the very essence of education is concentration of mind, not the collecting facts. If I had to do my education over again, and had any voice in the matter, I would not study facts at all. I would develop the power of concentration and detachment, and then with a perfect instrument I could collect facts at will. (VI. 38-39)

    The education which does not help the common mass of people to equip themselves for the struggle for life, which does not bring out strength of character, a spirit of philanthropy, and the courage of a lion - is it worth the name? Real education is that which enables one to stand on his own legs. (VII. 147-48)

    Education is not the amount of information that is put into your brain and runs riot there, undigested all your life. We must have life-building, man-making, character-making, assimilation of ideas. If you have assimilated five ideas and made them your life and character, you have more education than any man who has got by heart a whole library. (III. 302)

    Knowledge is inherent in man; no knowledge comes from outside; it is all inside. ...We say Newton discovered gravitation. Was it sitting anywhere in a corner waiting for him? It was in his own mind; the time came and he found it out. All knowledge that the world has ever received comes from the mind; the infinite library of the universe is in your own mind. The external world is simply the suggestion, the occasion, which sets you to study your own mind. (I. 28)

    Every one wants to command, and no one wants to obey; and this is owing to the absence of that wonderful brahmacarya system of yore. First, learn to obey. The command will come by itself. Always first learn to be a servant, and then you will be fit to be a master. (III. 134-35)

    Education, education, education alone! Traveling through many cities of Europe and observing in them the comforts and education of even the poor people, there was brought to my mind the state of our own poor people, and I used to shed tears. What made the difference? Education was the answer I got. (IV. 483)

    What we want is this sraddha. Unfortunately, it has nearly vanished from India, and this is why we are in our present state. What makes the difference between man and man is the difference in this sraddha and nothing else. What makes one man great and another weak and low is this sraddha. (III. 319)

    Give up the awful disease that is creeping into our national blood, that idea of ridiculing everything, that loss of seriousness. Give that up. Be strong and have this sraddha, and everything else is bound to follow. (III. 320)

    The only service to be done for our lower classes is to give them eduction, to develop their lost individuality, ... Give them ideas - that is the only help they require, and then the rest must follow as the effect. Ours is to put the chemicals together, the crystallization comes in the law of nature. ... Now if the mountain does not come to Mohammed, Mohammed must go to the mountain. If the poor boy cannot come to education, education must go to him. (IV. 362-63)

    We want that education by which character is formed, strength of mind is increased, the intellect is expanded, and by which one can stand on one's feet. (V. 342)

    In that education, as a result of which the will, being continuously choked by force through generations, is now well-nigh killed out; under whose sway, why mention new ideas, even the old ones are disappearing one by one; is that education which is slowly making man a machine? It is more blessed, in my opinion, even to go wrong, impelled by one's free will and intelligence, than to be good as an automation. (IV. 490)

    What we want are western science coupled with Vedanta, brahmacarya as the guiding motto, and also sradda and faith in one's own self. ... Vedanta says that withi9n man is all knowledge - even in a boy it is so - sand it requires only an awakening, and that much is the work of a teacher. ... But the root is religion. Religion is as the rice, and everything else, like the curries. Taking only curries causes indigestion, and so is the case with taking rice alone. (V. 366)

    Do  you see, simple by the observance of strict brahmacarya (continence), all learning can be mastered in a very short time - one has an unfailing memory of what one hears or knows but once. It is owing to this want of continence that everything is on the brink of ruin in our country. (VII. 244)

    My idea of education is personal contact with the teacher - gurugrah-vasa. Without the personal life of a teacher, there would be no education. Take your universities. What have they done during the fifty years (this was told at Madras in 1897)  of their existence? They have not produced one original man. They are merely an examining body. The idea of the sacrifice for the common weal is not yet developed in our nation. (V. 224)

    Truth does not pay homage to any society, ancient and modern. Society has to pay  homage to Truth or die. Societies should be moulded upon truth, and truth has not to adjust itself to society. ... That society is the greatest, where the highest truths become practical. That is my opinion; and if society is not fit for the highest truths, make it so; and the sooner, the better. (II. 84-85)

    I say, liberate, undo the shackles of people as much as you can. ... When you would be able to sacrifice all desire for happiness for the sake of society, then you would be the Buddha, then you would be free. (IV. 491)

    Three things are necessary to make every man great, every nation great:
    1. Conviction of the powers of goodness.
    2. Absence of jealousy and suspicion.
    3. Helping all who are trying to be and do good. (VIII. 299)

    If your ideal is matter, matter shalt thou be. Behold! Our ideal is the Spirit. That alone exists. Nothing else exists, and like Him, we live for ever. (VIII. 72)

    The Hindu man drinks religiously, sleeps religiously, walks religiously, marries religiously, robs religiously. ... Each nation has a mission for the world. So long as that mission is not hurt, that nation lives, despite every difficulty. But as soon as its mission is destroyed, the nation collapses. (VIII. 74-75)




    

Sunday, October 31, 2010

Vivekananda: Man The Maker of His Destiny

MAN THE MAKER OF HIS DESTINY

Complete Works of Swami Vivekananda: http://www.advaitaashrama.org/cw/

    What do I care if Mohammed was a goodman, or Buddha! Does that alter my own goodness or evil? Let us be good for our own sake on our own responsibility! Not because somebody way back there was good! (Reminiscences of Swami Vivekananda, p. 273)

    We are responsible for what we are, and whatever we wish ourselves to be, we have the power to make ourselves. If what we are now has been the result of our own past actions, it certainly follows that whatever we wish to be in future can be produced by our present actions; so we have to know how to act. (I. 31)

    This human body is the greatest body in the universe, and a human being the greatest being. man is higher than all animals, than all angels; none is greater than man. (I. 142)

    Man is man, so long as he is struggling to rise above nature, and this nature is both internal and external. ... And if we read the history of nations between the lines, we shall always find that the rise of a nation comes with an increase in the number of such men; and the fall begins when this pursuit after the Infinite, however vain the Utilitarians may call it, has ceased. That is to say, the mainspring of the strength of every race lies in its spirituality, and the death of that race begins the day that spirituality wanes and materialism gains ground. (II. 64-65)

    This world is a great gymnasium where we come to make ourselves strong. (V. 410)

    All healthy social changes are the manifestations of the spiritual forces working within, and if these are strong and well adjusted, society will arrange itself accordingly. Each individual has to work out his own salvation; there is no other way, and so also with nations. ... It is very easy to point out the defects of institutions, all being more or less imperfect, but he is the real benefactor of humanity who helps the individual to overcome his imperfections under whatever institutions he may live. The individuals being raised, the nation and its institutions are bound to rise. (V. 415-16)

    You have to grow from inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul. (V. 410)

    Men in general lay all the blame of life on their fellowmen, or, failing that, on God, or they conjure up a ghost, and say it is fate. Where is fate, and who is fate? We reap what we sow. We are the makers of our own fate. None else has the blame, none has the praise. The wind is blowing; those vessels whose sails are unfurled catch it, and go forward on their way, but those which have their sails furled do not catch the wind. Is that the fault of the wind? (II. 224)

    Say, 'This misery that I am suffering is of my own doing, and that very thing proves that it will have to be undone by me alone.' That which I created, I can demolish; that which is created by someone else, I shall never be able to destroy. Therefore, stand up, be bold, be strong. Take the whole responsibility on your own shoulders, and know that you are the creator of your own destiny. All the strength and succour you want is within yourselves. (II. 225)

    Make your own future. 'Let the dead past bury its dead.' The infinite future is before you, and you must always remember that each word, thought, and deed lays up a store for you, and that as the bad thoughts and bad works are ready to spring upon  you like tigers, so also there is the inspiring hope that the good thoughts and good  deeds are ready with the power of a hundred thousand angels to defend you always and for ever. (II. 225)

    'Ours not to reason why, ours but to do and die.' Be of good cheer and believe that we are selected by the Lord to do great things, and we will do them. (V. 23)

    Unfortunately, in this life, the vast majority of persons are groping through this dark life without any ideal at all. If a man with an ideal makes a thousand mistakes, I am sure that the man without an ideal makes fifty thousand. Therefore, it is better to have an ideal. (II. 152)

    Man begins to struggle and fight against nature. He makes many mistakes, he suffers. But eventually, he conquers nature and realized his freedom. When he is free, nature becomes his slave. (VIII. 249)

    I disagree with the idea that freedom is obedience to the laws of nature. I do not understand what that means. According to the history of human progress, it is disobedience to nature that has constituted that progress. (VIII. 257)

    For the world can be good and pure, only if our lives are good and pure. It is an effect, and we are the means. Therefore, let us purify ourselves. Let us make ourselves perfect. (II. 9)

    What is the use of fighting and complaining? That will not help us to better things. He who grumbles at the little thing that has fallen to his lot to do, will grumble at everything. Always grumbling, he will lead a miserable life, and everything will be a failure. But that man who does his duty as he goes, putting his shoulder to the wheel, will see the light, and higher and higher duties will fall to his share. (V. 242)

    Do not fly away from the wheels of the world-machine, but stand inside it and learn the secret of work. Thorough proper work done inside, it is also possible to come out. (I. 115)

    Every thought that we think, every deed that we do, after a certain time becomes fine, goes into seed form, so to speak, and lives in the fine body in a potential form, and after a time, it emerges again and bears its results. These results condition the life of man. Thus he moulds his own life. Man is not bound by any other laws excepting those which he makes for himself. (II. 348)

    My ideal, indeed, can be put into a few words, and that is: to preach unto mankind their divinity, and how to make it manifest in every movement of life. (VII. 498)

    Purity, patience, and perseverance are the three essentials to success, and above all - love. (VI. 281)

    Life is ever expanding, contraction is death. The self-seeking man who is looking after his personal comforts and leading a lazy life - there is no room for him even in hell. (VI. 294)

    I am sure God will pardon a man who will use his reason and cannot believe, rather than a man who believes blindly instead of using the faculties He has given him. ... We must reason; and when reason proves to us the truth of these prophets and great men about whom the ancient books speak in every country, we shall believe in them. We shall believe in them when we see such prophets among ourselves. We shall then find that they were not peculiar men, but only illustrations of certain principles. (VI. 12-13)

    Why should you not try to hit the mark? We become wiser through failures. Time is infinite. Look at the wall. did the wall ever tell a lie? It is always the wall. Man tells a lie - and becomes a god, too. It is better to do something; never mind even if it proves to be wrong; it is better than doing nothing. The cow never tells a lie; but she remains a cow, all the time. Do something! (IV. 126-27)

    Go on doing good, thinking holy thoughts continuously, that is the only way to suppress base impressions. Never say any man is hopeless, because he only represents a character, a bundle of habits, which can be checked by new and better ones. Character is repeated habits, and repeated habits alone can reform character. ... The chaste brain has tremendous  energy and gigantic will power. (I. 208, 263)

    We can overcome the difficulty by constant practice. We must learn that nothing can happen to us, unless we make ourselves susceptible to it. (II. 7)

    I was once traveling in the Himalayas and the long road stretched before us. We poor monks cannot get anyone to carry us, so we had to make all the way on foot. There was an old man with us. ... He said, 'Oh, Sir, how to cross it; I cannot walk any more; my chest will break.' I said to him, 'Look down at your feet.' He did so, and I said, 'The road that is under your feet is the road that you have passed over and is the same road that you see before you; it will soon be under your feet.' The highest things are under your feet, because you are Divine Stars. (VIII. 186-87)

    'It is the coward and the fool who says, "This is fate"' - so says the Sanskrit proverb. But it is the strong man who stands up and says, 'I will make my fate'. It is people who are getting old who talk of fate. Young men generally do not come to astrology. (VIII. 184)

    If you really want to judge of the character of a man, look not at his great performances. Every fool may become a hero at one time or another. Watch a man do his most common actions; those are indeed the things which will tell you the real character of a great man. Great occasions rouse even the lowest of human beings to some kind of greatness, but he alone is the really great man whose character is great always, the same wherever he be. (I. 29)

    Every good thought that we send to the world, without thinking of any return, will be stored up there and break one link in the chain, and make us purer and purer, until we become the purest of mortals. (I. 116)

    If you project hatred and jealousy, they will rebound on you with compound interest. No power can avert them; when once you have put them in motion, you will have to bear them. Remembering this will prevent you from doing wicked things. (I. 262)

    Everything is conscious which rebels against nature: there, consciousness is manifested. Just try to kill a little ant, even it will once resist to save its life. Where there is struggle, where there is rebellion, there is the sign of life, there consciousness is manifested. (VI. 453)

    Isn't it man that makes money? Where did you ever hear of money making man? If you can make your thoughts and words perfectly at one, if you can, I say, make yourself one in speech and action, money will pour in at your feet of itself, like water. (VI. 455)

    The road to the Good is the roughest and steepest in the universe. It is a wonder that so many succeed, no wonder that so many fall. Character has to be established through a thousand stumbles. (VIII. 382)

    Each work has to pass through these stages -  ridicule, opposition, and then acceptance. Each man who thinks ahead of his time is sure to be misunderstood. So opposition and persecution are welcome, only I have to be steady and pure and must have immense faith in God, and all these will vanish. (V. 91)

    Each soul is potentially divine. The goal is to manifest this divinity within by controlling nature, external and internal. Do this either by work, or worship, or psychic control, or philosophy - by one or more or all of these - and be free. This is the whole of religion. Doctrines, or dogmas, or rituals, or books, or temples, or forms, are but secondary details. (I. 257)

    Each one thinks his method is best. Very good! But remember, it may be good for you. One food which is very indigestible to one is very digestible to another. Because it is good for you, do not jump to the conclusion that your method is everybody's method, that Jack's coat fits John and Mary. All the uneducated, uncultured, unthinking men and women have been put into that sort of strait jacket! Think for yourselves. Become atheists! Become materialists! That would be better. Exercise the mind! What right have you to say that this man's method is wrong? It may be wrong for you. That is to say, if you undertake the method, you will be degraded; but that does not mean that he will be degraded. Therefore, if you have knowledge and see a man weak, do not condemn him. Go to his level and help him if you can. He must grow. I can put five bucket-full of knowledge into his head in five hours. But what good will it do? He will be a little worse than before. (I. 470)

    Go and preach to all: 'Arise, awake, sleep no more; within each of you, there is the power to remove all wants and all miseries. Believe this, and that power will be manifested.' ... If you can think that infinite power, infinite knowledge, and indomitable energy lie within you, and if you can bring out that power, you can also become like me. (VI. 454)

Vivekananda Quotes on the Powers of the Mind

POWERS OF THE MIND 

Complete Works of Swami Vivekananda: http://www.advaitaashrama.org/cw/

    Take up one idea. Make that one idea your life - think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone. This is the way to success. ... If we really want to be blessed, and make others blessed, we must go deeper. (I. 177)

    All the great prophets, saints, and seers of the world - what did they do? In one span of life, they lived the whole life of humanity, traversed the whole length of time that it takes ordinary humanity to come to perfection. In one life, they perfect themselves; they have no thought for anything else, never live a moment for any other idea, and thus the way is shortened for them. This is what is meant by concentration, intensifying the power of assimilation, thus shortening the time. (I. 157)

    The more this power of concentration, the more knowledge is acquired, because this is the one and only method of acquiring knowledge. Even the lowest shoeblack, if he gives more concentration, will black shoes better; the cook with concentration will cook a meal all the better. In making money, or in worshiping God, or in doing anything, the stronger the power of concentration, the better will that thing be done. This is the one call, the one knock, which opens the gates of nature, and lets out floods of light. (II. 391)

    How has all the knowledge in the world been gained but by the concentration of the powers of the mind? The world is ready to give up its secrets, if we only know how to knock, how to give it the necessary blow. The strength and force of the blow come through concentration. There is no limit to the power of the human mind. The more concentrated it is, the more power is brought to bear on one point; that is the secret. (I. 130-31)

    No force can be created; it can only be directed. Therefore, we must learn to control the grand powers that are already in our hands, and by will power make them spiritual, instead of merely animal. Thus it is clearly seen that chastity is the cornerstone of all morality and of all religion. (VIII. 46)

    Free! We who cannot, for a moment, govern our own minds, nay, cannot hold our minds on a subject, focus it on a point to the exclusion of everything else, for a moment! Yet we call ourselves free. Think of it! ... The mind uncontrolled and unguided will drag us down, down, for ever -  rend us, kill us; and the mind controlled and guided will save us, free us. (VI. 30)

    The main difference between men and the animals is the difference in their powers of concentration. All success in any line of work is the result of this. ... The difference in their power of concentration also constitutes the difference between man and man. compare the lowest with the highest man. The difference is in the degree of concentration. (VI. 37)

    Ninety per cent of thought-force is wasted by the ordinary human being, and therefore, he is constantly committing blunders; the trained man or mind never makes a mistake. (VI. 123-24)

    What work do you expect from men of little hearts? Nothing in the world! You must have an iron will if you would cross the ocean. You must be strong enough to pierce mountains. (VI. 297)

    Good and evil thoughts are each a potent power, and they fill the universe. As vibration continues, so thought remains in the form of thought until translated into action. for example, force is latent in the man's arm until he strikes a blow, when he translated it into activity. We are the heirs of good and evil thought. If we make ourselves pure and the instruments of good thoughts, these will enter us. The good soul will not be receptive to evil thoughts. (VI. 134)

    In the history of mankind, you will find that there come the Messengers, and that from their very birth their mission is found and formed. The whole plan is there, laid down; and you see them swerving not one inch from that. Because they come with a mission, they come with a message. ... When they speak, each word is direct; it bursts like a bomb-shell. What is in the word, unless it has the Power behind? What matters it what language you speak, and how you arrange your language? What matters it whether you speak correct grammar or with fine rhetoric? What matters it  whether your language is ornamental or not? The question: Whether or not you have anything to give? It is a question of giving and taking, and not listening. Have you anything to give? - that is the first question. If you have, then, give. (IV. 122-24)

    Whatever you do, devote your whole mind, heart, and soul to it. I once met a great sannyasin, who cleansed his brass cooking utensils, making them shine like gold, with as much care and attention as he bestowed on his worship and meditation. (Life of Swami Vivekananda, p. 284)

    How to attain purity living this life? Shall we all go to the forest caves? What good would it do? If the mind is not under control, it is no use living in a cave because the same mind will bring all disturbances there. We will find twenty devils in the cave because all the devils are in the mind. If the mind is under control, we can have the cave anywhere, wherever we are.
    It is our own mental attitude which makes the world what it is for us. Our thoughts make things beautiful, our thoughts make things ugly. The whole world is in our own minds. Learn to see things in the proper light. (I. 440-41)

Friday, October 29, 2010

Vivekananda Quotes on Faith and Strength

FAITH AND STRENGTH

Complete Works of Swami Vivekananda: http://www.advaitaashrama.org/cw/

    He is an atheist who does not believe in himself. The old religions said that he was an atheist who did not believe in God. The new religion says that he is an atheist who does not believe in himself. (II. 301)

    The history of the world is the history of a few men who had faith in themselves. That faith calls out the divinity within. You can do anything. You fail only when you do not strive sufficiently to manifest infinite power. As soon as a man or a nation loses faith, death comes. (VII. 228)

    Faith, faith, faith in ourselves, faith, faith in God, this is the secret of greatness. If you have faith in all the three hundred and thirty millions of your mythological gods, and in all the gods which foreigners have now and again introduced into your midst, and still have no faith in yourselves, there is no salvation for you. (III. 190)

    Never think there is anything impossible for the soul. It is the greatest heresy to think so. If there is sin, this is the only sin - to say that you are weak, or others are weak. (II. 308)

    Whatever you think, that you will be. If you think yourselves weak, weak you will be; if you think yourselves strong, strong you will be. (III. 130)

    Be free; hope for nothing from any one. I am sure if you look back upon your lives, you will find that you were always vainly trying to get help from others, which never came. All the help that has come was from within yourselves. (II. 324)

    Never say, 'No'; never say, 'I cannot', for you are infinite. Even time and space are as nothing compared with your nature. You can do anything and everything, you are almighty. (II. 300)

    Ye are the children of God, the sharers of immortal bliss, holy and perfect beings. Ye divinities on earth - sinners! It is a sin to call a man so; it is a standing libel on human nature. Come up, O lions, and shake off the delusion that you are sheep; you are souls immortal, spirits free, blest and eternal. (I. 11)

    Never mind the struggles, the mistakes. I never heard a cow tell a lie, but it is only a cow - never a man. So never mind these failures, these little backslidings; hold the ideal a thousand times; and if you fail a thousand times make the attempt once more. (II. 152)

    The remedy for weakness is not brooding over weakness, but thinking of strength. Teach men of the strength that is already within them. (II. 300)

    If there is one word that you find coming like a bomb from the Upanisads, bursting like a bomb-shell upon masses of ignorance, it is the word, fearlessness. (III. 160)

    If you look, you will find that I have never quoted anything but the Upanisads. And of the Upanisads, it is only that one idea strength. The quintessence of the Vedas and Vedanta and all lies in that one word. (VIII. 267)

    Be strong, my young friends, that is my advice to you. You will be nearer to heaven through football than through the study of the Gita. These are bold words, but I have to say them, for I love you. I know where the shoe pinches. I have gained a litle experience. You will understand Gita better with your biceps, you muscles, a little stronger. (III. 242)

    This is the one question I put to every man... Are you strong? Do you feel strength? - for I know it is truth alone that gives strength... Strength is the medicine for the world's disease. (II. 201)

    This is the great fact: Strength is life; weakness is death. Strength is felicity, life eternal, immortal; weakness is constant strain and misery, weakness is death. (II. 3)

    To succeed, you must have tremendous perseverance, tremendous will. 'I will drink the ocean', says the persevering soul, 'at my will, mountains will crumble up.' Have that sort of energy, that sort of will; work hard, and you will reach the goal. (I. 178)

    Men, men, these are wanted: everything else will be ready, but strong, vigorous, believing men, sincere to the backbone, are wanted. A hundred such and the world becomes revolutionized. (III. 223-24)

    Are not drums made in the country? Are not trumpets and kettle-drums available in India? Make the boys hear the deep-toned sound of these instruments. Hearing from boyhood the sound of these effeminate forms of music, ... the country is well-nigh converted into a country of women. (VII. 232)

    Death is better than a vegetating ignorant life; it is better to die on the battle-field than to live a life of defeat. (II. 124)

    Come, do something heroic. Brother, what if you do not attain mukti, what if you suffer damnation a few times? Is the saying untrue: 'There are some saints who, full of holiness in thought, word, and deed, please the whole world by their numerous beneficent acts, and who develop their own hearts by magnifying an atom of virtue in others as if it were as great as a mountain'? (VI. 314-15)

    Can anything be done unless everybody exerts himself to his utmost? 'It is the man of action, the lion-heart, that the Goddess of wealth resorts to.' No need of looking behind. FORWARD! We want infinite energy, infinite zeal, infinite courage, and infinite patience, then only will great things be achieved. (VI. 383-84)

    Be not in despair; the way is very difficult, like walking on the edge of a razor; yet despair not, arise, awake, and find the ideal, the goal. (II. 124)

    Why weepest thou, brother? Their is neither death nor disease for thee. Why weepest thou, brother? There is neither misery nor misfortune for thee. Why weepest thou, brother? Neither change nor death was predicted of thee. Thou art Existence Absolute... Be you own self. (V. 275)

    Let people say whatever they like, stick to your own convictions, and rest assured, the world will be at your feet. They say, 'Have faith in this fellow or that fellow', but I say, 'Have faith in yourself first', that's the way. Have faith in yourself - all power is in you - be conscious and bring it out. Say, 'I can do everything'. 'Even the poison of a snake is powerless, if you can firmly deny it.' (VI. 274)

    Once when I was in Varanasi, I was passing through a place where there was a large tank of water on one side and a high wall on the other. It was in the grounds where there were many monkeys. The monkeys of Varanasi are huge brutes and are sometimes surly. They now took it into their heads not to allow me to pass through their street, so they howled and shrieked and clutched at my feet as I passed. As they pressed closer, I began to run, but the faster I ran, the faster came the monkeys, and they begann to bite at me. It seemed impossible to escape, but just then I met a stranger who called  who to me, 'Face the brutes'. I turned and faced the monkeys, and they fell back and finally fled. That is the lesson for all life -  face the terrible, fact it boldly. (I. 338)

    Stand up and fight! Not one step back, that is the idea. Fight it out, whatever comes. Let the stars move from the spheres! Let the whole world stand against us! Death means only a change of garment. What of it? Thus fight! You gain nothing by becoming cowards. Taking a step backward, you do not avoid any misfortune. You have cried to all the gods in the world. has misery ceased? ...The gods come to help you when you have succeeded. So what is the use? Die game. You are infinite, deathless, birthless. Because you are infinite spirit, it does not befit you to be a slave. Arise! Awake! Stand up and fight! (I. 461)

Thursday, October 28, 2010

Linux Kernel Developer FAQs

1. What is a semaphore?
Semaphores in Linux are sleeping locks. When a task attempts to acquire a semaphore that is already held, the semaphore places the task onto a wait queue and puts the task to sleep. The processor is then free to execute other code. When the processes holding the semaphore release the lock, one of the tasks on the wait queue is awakened so that it can then acquire the semaphore. Listing of the semaphore methods is:

sema_init(struct semaphore *, int)
Initializes the dynamically created semaphore to the given count

init_MUTEX(struct semaphore *)
Initializes the dynamically created semaphore with a count of one

init_MUTEX_LOCKED(struct semaphore *)
Initializes the dynamically created semaphore with a count of zero (so it is initially locked)

down_interruptible(struct semaphore *)
Tries to acquire the given semaphore and enter interruptible sleep if it is contended

down(struct semaphore *)
Tries to acquire the given semaphore and enter uninterruptible sleep if it is contended

down_trylock(struct semaphore *)
Tries to acquire the given semaphore and immediately return nonzero if it is contended

up(struct semaphore *)
Releases the given semaphore and wakes a waiting task, if any

2. What is the difference between semaphore and mutex?
Mutex can be released only by thread that had acquired it, while you can signal semaphore from any other thread (or process), so semaphores are more suitable for some synchronization problems like producer-consumer.

The mutex is similar to the principles of the binary semaphore with one significant difference: the principle of ownership. Ownership is the simple concept that when a task locks (acquires) a mutex only it can unlock (release) it. If a task tries to unlock a mutex it hasn’t locked (thus doesn’t own) then an error condition is encountered and, most importantly, the mutex is not unlocked. If the mutual exclusion object doesn't have ownership then, irrelevant of what it is called, it is not a mutex.

3. Discuss the TCP connection and termination sequence.
To establish a connection, TCP uses a three-way handshake. Before a client attempts to connect with a server, the server must first bind to a port to open it up for connections: this is called a passive open. Once the passive open is established, a client may initiate an active open. To establish a connection, the three-way (or 3-step) handshake occurs:
  1. SYN: The active open is performed by the client sending a SYN to the server. It sets the segment's sequence number to a random value A.
  2. SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number (A + 1), and the sequence number that the server chooses for the packet is another random number, B.
  3. ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value i.e. A + 1, and the acknowledgement number is set to one more than the received sequence number i.e. B + 1.
At this point, both the client and server have received an acknowledgment of the connection.



The connection termination phase uses, at most, a four-way handshake, with each side of the connection terminating independently. When an endpoint wishes to stop its half of the connection, it transmits a FIN packet, which the other end acknowledges with an ACK. Therefore, a typical tear-down requires a pair of FIN and ACK segments from each TCP endpoint.

4. What is the relationship between RTP, RTCP and RTSP?
RTP is a transport protocol for the delivery of real-time data,including streaming audio and video. RTCP is a part of RTP and helps with lip synchronization and QOS management, among others. RTSP is a control protocol for initiating and directing delivery of streaming multimedia from media servers, the "Internet VCR remote control protocol".

RTSP does not deliver data, though the RTSP connection may be used to tunnel RTP traffic for ease of use with firewalls and other network devices. RTP and RTSP will likely be used together in many systems, but either protocol can be used without the other. The RTSP specification contains a section on the use of RTP with RTSP.

RTSP does control / signalling, and is _not_ a transport protocol. The streams must be transported using another protocol, such as RTP or HTTP. RTSP is commonly used to help negotiate an audiovideo setup to decide what transport protocol and bit rate etc. is to be used.

5. How does a Linux process internally switches from User mode to Kernel mode?
Nearly all system calls [are] invoked from C programs by calling a library procedure. The library procedure executes a TRAP instruction to switch from user mode to kernel mode and start execution. The mechanism for generating software interrupts is the INT instruction. This is an Intel x86 opcode that interrupts the current program execution, saves the system registers, and then jumps to a specific interrupt handler.

After the handler has finished, the system registers are restored and the execution with the calling program is resumed. The INT instruction thus acts as (sort of) an alternative calling technique. Unlike ordinary procedure calls, which pass their args on the stack, interrupts store any needed args in registers.

An interrupt however, must have any needed arguments loaded into general registers first. The register assignments for the syscall handlers are as follows:
  • eax -- syscall #
  • ecx -- number of args (0-16)
  • edx -- pointer to buffer containing args from first to last
After these registers have been set, interrupt 99 is called. What is the significance of the value 99? None really -- this is simply the interrupt number selected by the kernel for handling syscalls. 

Each syscall has an entry point defined by a small assembly language function. Therefore, the syscall interface is an assembly file (called syscalls.S) containing a long list of functions, one for each syscall that has been defined.  This file should look like this: 

.globl sys_null
.type sys_null,@function
.align 8
sys_null:
 movl  $0, %eax        ; syscall #0
 movl  $0, %ecx        ; no args
 lea   4(%esp), %edx   ; pointer to arg list
 int   $99             ; invoke syscall handler
 ret                   ; return
.globl sys_mount
.type sys_mount,@function
.align 8
sys_mount:
 movl  $1, %eax        ; syscall #1
 movl  $4, %ecx        ; mount takes 4 args
 lea   4(%esp), %edx   ; pointer to arg list
 int   $99             ; invoke syscall handler
 ret                   ; return
. . .
The assignment of system services to syscall numbers is arbitrary. That is, it doesn't really matter which function is syscall #0, syscall #1, syscall #2, etc. so long as everyone is in agreement about the mapping. This mapping is defined in the syscalls.S assembly listing above, and much be matched item-for-item in the C interface header file. For our kernel, the C header is ksyscalls.h which uses an enum to define tags for each syscall:

enum {
    SYSCALL_NULL = 0,
    SYSCALL_MOUNT,
    SYSCALL_UNMOUNT,
    SYSCALL_SYNC,
    SYSCALL_OPEN,
    . . .
};
Exception Types:
  • fault - the return address points to the instruction that caused the exception. The exception handler may fix the problem and then restart the program, making it look like nothing has happened.
  • trap - the return address points to the instruction after the one that has just completed.
  • abort - the return address is not always reliably supplied. A program which causes an abort is never meant to be continued.
 The 256 exception handlers that are loaded into the IDT are almost identical. After pushing the specific interrupt number, they all implement the same code sequence:
  1. save all registers (including system registers)
  2. call i386_handle_trap
  3. restore all registers previously saved
  4. return
Because of this, the assembly file that defines these handlers, arch_interrupts.S, is also written largely as a collection of #define macros.The function i386_handle_trap() serves as the master exception handler. As such, it handles all system interrupts, not just syscalls. However, we're interested specifically in the section that deals with interrupt 99, the syscalls handler. 

The syscalls are handled in the case of the interrupt number 99. Again, there's no particular significance to the number 99. The Intel documentation allows for interrupt numbers 32-255 to be used freely by the OS for whatever purpose.


The highlights of the code are:
  1. thread_atkernel_entry() is called upon entering kernel mode
  2. the number of args (in ecx) and the argv address (in edx) are checked for validity (e.g. a kernel address is bad since syscalls are only intended for user apps)
  3. user_memcpy is called to copy the args from the user stack to kernel memory
  4. if all went well, the syscall dispatcher is called, passing the syscall # (stored in eax)
  5. a 64-bit error code in returned in the [eax,edx] pair
  6. thread_atkernel_exit() is called as kernel mode is exited.
 The routine syscall_dispatcher() is a core kernel function that finally binds the syscall numbers to their corresponding internal implementations. Here is a snippet of the syscalls.c file that contains the dispatcher:
 
int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_ret)
{
    switch(call_num) {
        case SYSCALL_NULL:
            *call_ret = 0;
            break;
        case SYSCALL_MOUNT:
            *call_ret = user_mount((const char *)arg0, (const char *)arg1,
                                   (const char *)arg2, (void *)arg3);
            break;
        case SYSCALL_UNMOUNT:
            *call_ret = user_unmount((const char *)arg0);
            break;
        case SYSCALL_SYNC:
            *call_ret = user_sync();
            break;
  
        . . .
  
    }
    return INT_RESCHEDULE;
}
 
7. Describe ways to reduce interrupt latency.
Sound programming techniques coupled with proper RTOS interrupt architecture can ensure the minimal response time. The recipe:
1. Keep ISRs simple and short.
2. Do not disable interrupts.
3.Avoid instructions that increase latency.
4. Avoid improper use of operating system API calls in ISRs.
5. Properly prioritize interrupts relative to threads. 
 
8.  What is top-half and bottom-half processing? 
Often a substantial amount of work must be done in response to a device interrupt, but interrupt handlers need to finish up quickly and not keep interrupts blocked for long. Linux (along with many other systems) resolves this problem by splitting the interrupt handler into two halves.
 
The so-called top half is the routine that actually responds to the interrupts, the one you register with request_irq. The bottom half is a routine that is scheduled by the top half to be executed later, at a safer time. 
 
The big difference between the top-half handler and the bottom half is that all interrupts are enabled during execution of the bottom half, that's why it runs at a safer time. In the typical scenario, the top half saves device data to a device-specific buffer, schedules its bottom half, and exits: this operation is very fast. 
 
The bottom half then performs whatever other work is required, such as awakening processes, starting up another I/O operation, and so on. This setup permits the top half to service a new interrupt while the bottom half is still working.
9. What are the different mechanisms to implement bottom halves in ISRs?
The Linux kernel has two different mechanisms that may be used to implement bottom-half processing. Tasklets are often the preferred mechanism for bottom-half processing; they are very fast, but all tasklet code must be atomic. The alternative to tasklets is workqueues, which may have a higher latency but that are allowed to sleep.
 
Tasklets must be declared with the DECLARE_TASKLET macro:
DECLARE_TASKLET(name, function, data);

name is the name to be given to the tasklet, function is the function that is called to execute the tasklet (it takes one unsigned long argument and returns void), and data is an unsigned long value to be passed to the tasklet function.

The function tasklet_schedule is used to schedule a tasklet for running.

Workqueues invoke a function at some future time in the context of a special worker process. Since the workqueue function runs in process context, it can sleep if need be. You cannot, however, copy data into user space from a workqueue, unless you use the advanced techniques. The worker process does not have access to any other process's address space.
 
a work_struct structure, is declared and initialized with the following:
static struct work_struct short_wq;

    /* this line is in short_init(  ) */
    INIT_WORK(&short_wq, (void (*)(void *)) short_do_tasklet, NULL);
 
Call schedule_work to arrange the bottom-half processing. 
/* Queue the bh. Don't worry about multiple enqueueing */
    schedule_work(&short_wq);